@viewfly/core 3.0.0-alpha.0 → 3.0.0-alpha.1

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/dist/index.esm.js CHANGED
@@ -1662,7 +1662,7 @@ var NativeRenderer = class {};
1662
1662
  //#endregion
1663
1663
  //#region src/base/renderer.ts
1664
1664
  var listenerReg = /^on[A-Z]/;
1665
- var nativeNodeRefRecord = /* @__PURE__ */ new Map();
1665
+ var nativeNodeRefRecord = /* @__PURE__ */ new WeakMap();
1666
1666
  function createRenderer(component, nativeRenderer, namespace) {
1667
1667
  let isInit = true;
1668
1668
  return function render(host) {
@@ -1890,9 +1890,12 @@ function cleanView(nativeRenderer, atom, needClean) {
1890
1890
  }
1891
1891
  if (atom.type === ElementAtomType) {
1892
1892
  const record = nativeNodeRefRecord.get(atom);
1893
- if (record) record.forEach((fn) => {
1894
- if (typeof fn === "function") fn();
1895
- });
1893
+ if (record) {
1894
+ nativeNodeRefRecord.delete(atom);
1895
+ record.forEach((fn) => {
1896
+ if (typeof fn === "function") fn();
1897
+ });
1898
+ }
1896
1899
  }
1897
1900
  cleanChildren(atom, nativeRenderer, needClean);
1898
1901
  }
@@ -2016,9 +2019,11 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
2016
2019
  });
2017
2020
  context.host = nativeNode;
2018
2021
  context.isParent = false;
2019
- const refEffects = /* @__PURE__ */ new Map();
2020
- nativeNodeRefRecord.set(atom, refEffects);
2021
- applyRefs(bindingRefs, nativeNode, refEffects);
2022
+ if (bindingRefs) {
2023
+ const refEffects = /* @__PURE__ */ new Map();
2024
+ nativeNodeRefRecord.set(atom, refEffects);
2025
+ applyRefs(bindingRefs, nativeNode, refEffects);
2026
+ }
2022
2027
  }
2023
2028
  function createTextNode(nativeRenderer, atom, context) {
2024
2029
  const nativeNode = nativeRenderer.createTextNode(atom.jsxNode, atom.namespace);
@@ -2037,6 +2042,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
2037
2042
  reuseElementChildrenView(nativeRenderer, newAtom, context);
2038
2043
  return;
2039
2044
  }
2045
+ let unBindRefs;
2040
2046
  let bindRefs;
2041
2047
  let updatedChildren = false;
2042
2048
  comparePropsWithCallbacks(oldVNode.props, newVNode.props, (key, oldValue) => {
@@ -2057,7 +2063,10 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
2057
2063
  if (typeof oldValue === "function") nativeRenderer.unListen(nativeNode, key, oldValue, isSvg);
2058
2064
  return;
2059
2065
  }
2060
- if (key === "ref") return;
2066
+ if (key === "ref") {
2067
+ unBindRefs = oldValue;
2068
+ return;
2069
+ }
2061
2070
  nativeRenderer.removeProperty(nativeNode, key, isSvg);
2062
2071
  }, (key, value) => {
2063
2072
  if (key === "children") {
@@ -2115,17 +2124,26 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
2115
2124
  return;
2116
2125
  }
2117
2126
  if (key === "ref") {
2127
+ unBindRefs = oldValue;
2118
2128
  bindRefs = newValue;
2119
2129
  return;
2120
2130
  }
2121
2131
  nativeRenderer.setProperty(nativeNode, key, newValue, isSvg);
2122
2132
  });
2123
2133
  if (!updatedChildren) newAtom.child = oldAtom.child;
2124
- let refEffects = nativeNodeRefRecord.get(oldAtom);
2125
- if (!refEffects) refEffects = /* @__PURE__ */ new Map();
2126
- nativeNodeRefRecord.delete(oldAtom);
2127
- nativeNodeRefRecord.set(newAtom, refEffects);
2128
- updateRefs(bindRefs, nativeNode, refEffects);
2134
+ if (bindRefs === unBindRefs) {
2135
+ const refEffects = nativeNodeRefRecord.get(oldAtom);
2136
+ if (refEffects) {
2137
+ nativeNodeRefRecord.delete(oldAtom);
2138
+ nativeNodeRefRecord.set(newAtom, refEffects);
2139
+ }
2140
+ } else {
2141
+ let refEffects = nativeNodeRefRecord.get(oldAtom);
2142
+ if (!refEffects) refEffects = /* @__PURE__ */ new Map();
2143
+ nativeNodeRefRecord.delete(oldAtom);
2144
+ nativeNodeRefRecord.set(newAtom, refEffects);
2145
+ updateRefs(bindRefs, nativeNode, refEffects);
2146
+ }
2129
2147
  }
2130
2148
  //#endregion
2131
2149
  //#region src/base/root.component.ts
package/dist/index.js CHANGED
@@ -2223,7 +2223,7 @@ var NativeRenderer = class {};
2223
2223
  //#endregion
2224
2224
  //#region src/base/renderer.ts
2225
2225
  var listenerReg = /^on[A-Z]/;
2226
- var nativeNodeRefRecord = /* @__PURE__ */ new Map();
2226
+ var nativeNodeRefRecord = /* @__PURE__ */ new WeakMap();
2227
2227
  function createRenderer(component, nativeRenderer, namespace) {
2228
2228
  let isInit = true;
2229
2229
  return function render(host) {
@@ -2451,9 +2451,12 @@ function cleanView(nativeRenderer, atom, needClean) {
2451
2451
  }
2452
2452
  if (atom.type === ElementAtomType) {
2453
2453
  const record = nativeNodeRefRecord.get(atom);
2454
- if (record) record.forEach((fn) => {
2455
- if (typeof fn === "function") fn();
2456
- });
2454
+ if (record) {
2455
+ nativeNodeRefRecord.delete(atom);
2456
+ record.forEach((fn) => {
2457
+ if (typeof fn === "function") fn();
2458
+ });
2459
+ }
2457
2460
  }
2458
2461
  cleanChildren(atom, nativeRenderer, needClean);
2459
2462
  }
@@ -2577,9 +2580,11 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
2577
2580
  });
2578
2581
  context.host = nativeNode;
2579
2582
  context.isParent = false;
2580
- const refEffects = /* @__PURE__ */ new Map();
2581
- nativeNodeRefRecord.set(atom, refEffects);
2582
- applyRefs(bindingRefs, nativeNode, refEffects);
2583
+ if (bindingRefs) {
2584
+ const refEffects = /* @__PURE__ */ new Map();
2585
+ nativeNodeRefRecord.set(atom, refEffects);
2586
+ applyRefs(bindingRefs, nativeNode, refEffects);
2587
+ }
2583
2588
  }
2584
2589
  function createTextNode(nativeRenderer, atom, context) {
2585
2590
  const nativeNode = nativeRenderer.createTextNode(atom.jsxNode, atom.namespace);
@@ -2598,6 +2603,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
2598
2603
  reuseElementChildrenView(nativeRenderer, newAtom, context);
2599
2604
  return;
2600
2605
  }
2606
+ let unBindRefs;
2601
2607
  let bindRefs;
2602
2608
  let updatedChildren = false;
2603
2609
  comparePropsWithCallbacks(oldVNode.props, newVNode.props, (key, oldValue) => {
@@ -2618,7 +2624,10 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
2618
2624
  if (typeof oldValue === "function") nativeRenderer.unListen(nativeNode, key, oldValue, isSvg);
2619
2625
  return;
2620
2626
  }
2621
- if (key === "ref") return;
2627
+ if (key === "ref") {
2628
+ unBindRefs = oldValue;
2629
+ return;
2630
+ }
2622
2631
  nativeRenderer.removeProperty(nativeNode, key, isSvg);
2623
2632
  }, (key, value) => {
2624
2633
  if (key === "children") {
@@ -2676,17 +2685,26 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
2676
2685
  return;
2677
2686
  }
2678
2687
  if (key === "ref") {
2688
+ unBindRefs = oldValue;
2679
2689
  bindRefs = newValue;
2680
2690
  return;
2681
2691
  }
2682
2692
  nativeRenderer.setProperty(nativeNode, key, newValue, isSvg);
2683
2693
  });
2684
2694
  if (!updatedChildren) newAtom.child = oldAtom.child;
2685
- let refEffects = nativeNodeRefRecord.get(oldAtom);
2686
- if (!refEffects) refEffects = /* @__PURE__ */ new Map();
2687
- nativeNodeRefRecord.delete(oldAtom);
2688
- nativeNodeRefRecord.set(newAtom, refEffects);
2689
- updateRefs(bindRefs, nativeNode, refEffects);
2695
+ if (bindRefs === unBindRefs) {
2696
+ const refEffects = nativeNodeRefRecord.get(oldAtom);
2697
+ if (refEffects) {
2698
+ nativeNodeRefRecord.delete(oldAtom);
2699
+ nativeNodeRefRecord.set(newAtom, refEffects);
2700
+ }
2701
+ } else {
2702
+ let refEffects = nativeNodeRefRecord.get(oldAtom);
2703
+ if (!refEffects) refEffects = /* @__PURE__ */ new Map();
2704
+ nativeNodeRefRecord.delete(oldAtom);
2705
+ nativeNodeRefRecord.set(newAtom, refEffects);
2706
+ updateRefs(bindRefs, nativeNode, refEffects);
2707
+ }
2690
2708
  }
2691
2709
  //#endregion
2692
2710
  //#region src/base/root.component.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.1",
4
4
  "description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",