pudui 0.0.3 → 0.0.4

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/dist/index.mjs +32 -0
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -753,6 +753,7 @@ function patchRenderNode(node, nextChild, context) {
753
753
  }
754
754
  function patchArrayRenderNode(node, nextChildren, context) {
755
755
  const normalizedChildren = normalizeChildren(nextChildren);
756
+ if (patchRemovedKeyedArrayRenderNode(node, normalizedChildren, context)) return node;
756
757
  if (shouldPatchKeyedArray(node.c, normalizedChildren)) return patchKeyedArrayRenderNode(node, reuseKeyedArrayChildren(node, normalizedChildren), context);
757
758
  if (patchSameLengthKeyedArrayRenderNode(node, normalizedChildren, context)) return node;
758
759
  const sharedLength = Math.min(node.c.length, normalizedChildren.length);
@@ -897,6 +898,37 @@ function patchSameLengthKeyedArrayRenderNode(node, normalizedChildren, context)
897
898
  node.c = nextNodes;
898
899
  return true;
899
900
  }
901
+ function patchRemovedKeyedArrayRenderNode(node, normalizedChildren, context) {
902
+ const oldLength = node.c.length;
903
+ const nextLength = normalizedChildren.length;
904
+ if (oldLength <= nextLength) return false;
905
+ const nextNodes = [];
906
+ const removedNodes = [];
907
+ let nextIndex = 0;
908
+ for (let oldIndex = 0; oldIndex < oldLength; oldIndex++) {
909
+ const oldNode = node.c[oldIndex];
910
+ const oldKey = readRenderNodeKey(oldNode);
911
+ if (oldKey === void 0) return false;
912
+ const nextChild = normalizedChildren[nextIndex];
913
+ if (nextChild !== void 0) {
914
+ const nextKey = readChildKey(nextChild);
915
+ if (nextKey === void 0) return false;
916
+ if (oldKey === nextKey) {
917
+ nextNodes.push(patchStableKeyedRenderNode(oldNode, nextChild, context));
918
+ nextIndex++;
919
+ continue;
920
+ }
921
+ }
922
+ removedNodes.push(oldNode);
923
+ }
924
+ if (nextIndex !== nextLength) return false;
925
+ for (const removedNode of removedNodes) {
926
+ cleanupRenderNode(removedNode);
927
+ removeRenderNode(removedNode);
928
+ }
929
+ node.c = nextNodes;
930
+ return true;
931
+ }
900
932
  function patchStableKeyedRenderNode(node, nextChild, context) {
901
933
  if (canSkipStableKeyedRenderNodePatch(node, nextChild, context)) return node;
902
934
  return patchRenderNode(node, nextChild, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pudui",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "A tiny JSX UI runtime built from the ground up.",
5
5
  "license": "MIT",
6
6
  "files": [