@fruit-ui/core 1.2.5 → 1.2.7

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/README.md CHANGED
@@ -64,7 +64,7 @@ Smaller apps don't always warrant heavyweight frameworks, but interfacing with t
64
64
  ## Getting started
65
65
 
66
66
  There are three ways to use FRUIT in your projects:
67
- - Download and copy the [Terser-compressed JS file](https://github.com/asantagata/fruit-ui/blob/main/core/dist/index.js) file into your project. (This is a compressed version built with Terser; you can just as well use the [non-compressed version](https://github.com/asantagata/fruit-ui/blob/main/core/src/index.js) which uses JSDoc annotations.) Then you can use `import * as fruit from "./modules/fruit.js"` or `<script type="module" src="./modules/fruit.js">` to access FRUIT in your JS apps.
67
+ - Download and copy the [Terser-compressed JS file](https://github.com/asantagata/fruit-ui/blob/main/core/dist/index.js) file into your project. (This is a compressed version built with Terser; you can just as well use the [non-compressed version](https://github.com/asantagata/fruit-ui/blob/main/core/src/index.js) which uses JSDoc annotations). Then you can use `import * as fruit from "./modules/fruit.js"` or `<script type="module" src="./modules/fruit.js">` to access FRUIT in your JS apps.
68
68
  - Access via browser loading, i.e., `import * as fruit from "https://cdn.jsdelivr.net/npm/@fruit-ui/core@latest/src/index.js"`.
69
69
  - With NPM installed, run `npm install @fruit-ui/core`. Then use `import * as fruit from "@fruit-ui/core"`.
70
70
 
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.7",
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
  }
@@ -634,6 +649,21 @@ function rerenderChildren(element, template, onMounts) {
634
649
  childEl.remove();
635
650
  }
636
651
  }
652
+ } else if (tmChildrenArray.length === 0 && elChildrenArray.length > 0) {
653
+ // delete all children
654
+ for (let i = elChildrenArray.length - 1; i >= 0; i--) {
655
+ let childEl = elChildrenArray[i];
656
+ if ('componentId' in childEl.dataset) delete thisRecord[childEl.dataset.componentId];
657
+ if ('binding' in childEl.dataset) delete this.bindings[childEl.dataset.binding];
658
+ childEl.remove();
659
+ }
660
+ } else if (tmChildrenArray.length > 0 && elChildrenArray.length === 0) {
661
+ // create all children
662
+ for (let i = 0; i < tmChildrenArray.length; i++) {
663
+ let childTm = tmChildrenArray[i];
664
+ const newChild = createElementFromElementable.call(this, childTm, onMounts);
665
+ element.appendChild(newChild);
666
+ }
637
667
  }
638
668
 
639
669
  // handle bindings