@fruit-ui/core 1.2.5 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +17 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fruit-ui/core",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "A vanilla JS toolkit for reactive UI",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://asantagata.github.io/fruit-ui/",
package/src/index.js CHANGED
@@ -116,7 +116,7 @@ function createThis(component) {
116
116
  state: {},
117
117
  setState: {},
118
118
  bindings: {},
119
- memo: structuredClone(component.memo)
119
+ memo: deepClone(component.memo)
120
120
  };
121
121
  }
122
122
 
@@ -472,6 +472,21 @@ function deepEqual(a, b) {
472
472
  } else return (a === b);
473
473
  }
474
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;
488
+ }
489
+
475
490
  /**
476
491
  * Returns true iff a component has a memo (functional or otherwise) and it is satisfied.
477
492
  * @param {This} this - the This.
@@ -483,7 +498,7 @@ function evaluateMemo(component) {
483
498
  // for functional memos: rerender if returns false
484
499
  if (typeof component.memo === 'function') return !!component.memo.call(this);
485
500
  const equal = deepEqual(component.memo, this.memo);
486
- this.memo = structuredClone(component.memo);
501
+ this.memo = deepClone(component.memo);
487
502
  return equal;
488
503
  } else return false;
489
504
  }