pudui 0.0.2 → 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 +42 -5
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -753,7 +753,9 @@ 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);
758
+ if (patchSameLengthKeyedArrayRenderNode(node, normalizedChildren, context)) return node;
757
759
  const sharedLength = Math.min(node.c.length, normalizedChildren.length);
758
760
  for (let index = 0; index < sharedLength; index++) node.c[index] = patchRenderNode(node.c[index], normalizedChildren[index], context);
759
761
  const parent = node.e.parentNode;
@@ -806,13 +808,17 @@ function canReuseKeyedChild(previousChild, nextChild) {
806
808
  function shallowEqualProps(previousProps, nextProps) {
807
809
  if (previousProps === nextProps) return true;
808
810
  if (previousProps === void 0) return false;
809
- const previousKeys = Object.keys(previousProps);
810
- const nextKeys = Object.keys(nextProps);
811
- if (previousKeys.length !== nextKeys.length) return false;
812
811
  const previousRecord = previousProps;
813
812
  const nextRecord = nextProps;
814
- for (const key of previousKeys) if (previousRecord[key] !== nextRecord[key] || !Object.hasOwn(nextProps, key)) return false;
815
- return true;
813
+ let previousKeyCount = 0;
814
+ for (const key in previousRecord) {
815
+ if (!Object.hasOwn(previousRecord, key)) continue;
816
+ previousKeyCount++;
817
+ if (previousRecord[key] !== nextRecord[key] || !Object.hasOwn(nextProps, key)) return false;
818
+ }
819
+ let nextKeyCount = 0;
820
+ for (const key in nextRecord) if (Object.hasOwn(nextRecord, key)) nextKeyCount++;
821
+ return previousKeyCount === nextKeyCount;
816
822
  }
817
823
  function patchKeyedArrayRenderNode(node, normalizedChildren, context) {
818
824
  if (patchSameLengthKeyedArrayRenderNode(node, normalizedChildren, context)) return node;
@@ -892,6 +898,37 @@ function patchSameLengthKeyedArrayRenderNode(node, normalizedChildren, context)
892
898
  node.c = nextNodes;
893
899
  return true;
894
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
+ }
895
932
  function patchStableKeyedRenderNode(node, nextChild, context) {
896
933
  if (canSkipStableKeyedRenderNodePatch(node, nextChild, context)) return node;
897
934
  return patchRenderNode(node, nextChild, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pudui",
3
- "version": "0.0.2",
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": [