Skip to content

Commit

Permalink
minor(hdom): intern strings
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Dec 12, 2018
1 parent 046ab20 commit 1dc6e72
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/hdom/src/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ const extractEquivElements =

const OBJP = Object.getPrototypeOf({});

const FN = "function";
const STR = "string";

/**
* Customized version @thi.ng/equiv which takes `__diff` attributes into
* account (at any nesting level). If an hdom element's attribute object
Expand All @@ -251,29 +254,29 @@ export const equiv =
return true;
}
if (a != null) {
if (typeof a.equiv === "function") {
if (typeof a.equiv === FN) {
return a.equiv(b);
}
} else {
return a == b;
}
if (b != null) {
if (typeof b.equiv === "function") {
if (typeof b.equiv === FN) {
return b.equiv(a);
}
} else {
return a == b;
}
if (typeof a === "string" || typeof b === "string") {
if (typeof a === STR || typeof b === STR) {
return false;
}
if ((proto = Object.getPrototypeOf(a), proto == null || proto === OBJP) &&
(proto = Object.getPrototypeOf(b), proto == null || proto === OBJP)) {
return !((<any>a).__diff === false || (<any>b).__diff === false) &&
equivObject(a, b, equiv);
}
if (typeof a !== "function" && a.length !== undefined &&
typeof b !== "function" && b.length !== undefined) {
if (typeof a !== FN && a.length !== undefined &&
typeof b !== FN && b.length !== undefined) {
return equivArrayLike(a, b, equiv);
}
if (a instanceof Set && b instanceof Set) {
Expand Down

0 comments on commit 1dc6e72

Please sign in to comment.