@fruit-ui/core 1.2.4 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +19 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -116,7 +116,7 @@ function createThis(component) {
|
|
|
116
116
|
state: {},
|
|
117
117
|
setState: {},
|
|
118
118
|
bindings: {},
|
|
119
|
-
memo:
|
|
119
|
+
memo: deepClone(component.memo)
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -450,7 +450,6 @@ function rerenderElementFromTemplate(element, template, onMounts) {
|
|
|
450
450
|
* @returns {boolean} whether they are equal.
|
|
451
451
|
*/
|
|
452
452
|
function deepEqual(a, b) {
|
|
453
|
-
if (a === b) return true;
|
|
454
453
|
if (typeof a !== typeof b) return false;
|
|
455
454
|
if (typeof a === 'function') return true;
|
|
456
455
|
if (typeof a === 'object' && a !== null) {
|
|
@@ -468,9 +467,24 @@ function deepEqual(a, b) {
|
|
|
468
467
|
} else {
|
|
469
468
|
const keysA = Object.keys(a), keysB = Object.keys(b);
|
|
470
469
|
if (keysA.length !== keysB.length) return false;
|
|
471
|
-
return keysB.every(keyB => keyB in a && deepEqual(
|
|
470
|
+
return keysB.every(keyB => keyB in a && deepEqual(a[keyB], b[keyB]));
|
|
472
471
|
}
|
|
473
|
-
} else return
|
|
472
|
+
} else return (a === b);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Deep clones a value.
|
|
477
|
+
* @param {*} value - the value.
|
|
478
|
+
* @returns {*} - the clone.
|
|
479
|
+
*/
|
|
480
|
+
function deepClone(value) {
|
|
481
|
+
if (typeof value === 'object') {
|
|
482
|
+
if (value === null) return null;
|
|
483
|
+
if (Array.isArray(value)) return value.map(deepClone);
|
|
484
|
+
if (value instanceof Set) return new Set([...value].map(deepClone));
|
|
485
|
+
if (value instanceof Map) return new Map(value.entries().map(([k, v]) => [deepClone(k), deepClone(v)]));
|
|
486
|
+
return Object.fromEntries(Object.entries(value).map(([k,v]) => [k, deepClone(v)]));
|
|
487
|
+
} else return value;
|
|
474
488
|
}
|
|
475
489
|
|
|
476
490
|
/**
|
|
@@ -484,7 +498,7 @@ function evaluateMemo(component) {
|
|
|
484
498
|
// for functional memos: rerender if returns false
|
|
485
499
|
if (typeof component.memo === 'function') return !!component.memo.call(this);
|
|
486
500
|
const equal = deepEqual(component.memo, this.memo);
|
|
487
|
-
this.memo =
|
|
501
|
+
this.memo = deepClone(component.memo);
|
|
488
502
|
return equal;
|
|
489
503
|
} else return false;
|
|
490
504
|
}
|