@3sln/dodo 0.0.6 → 0.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/vdom.js +35 -37
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3sln/dodo",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "A minimal, configurable virtual DOM library.",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/vdom.js CHANGED
@@ -13,7 +13,7 @@ class VNode {
13
13
  }
14
14
 
15
15
  key(k) {
16
- this.key = k;
16
+ this.k = k;
17
17
  return this;
18
18
  }
19
19
 
@@ -525,35 +525,33 @@ export default userSettings => {
525
525
 
526
526
  function cleanupTarget(target) {
527
527
  const state = target[NODE_STATE];
528
- if (state) {
529
- switch (state.vdom.type) {
530
- case ELEMENT_NODE:
531
- reconcileElementProps(target, {});
532
- cleanupTargetChildren(target);
533
- delete target[NODE_STATE];
534
- break;
535
- case OPAQUE_NODE:
536
- reconcileElementProps(target, {});
537
- delete target[NODE_STATE];
538
- break;
539
- case ALIAS_NODE:
540
- cleanupTargetChildren(target);
541
- delete target[NODE_STATE];
542
- break;
543
- case SPECIAL_NODE:
544
- delete target[NODE_STATE];
545
- try {
546
- state.vdom.tag.detach?.(target);
547
- } catch (err) {
548
- console.error(err);
549
- }
550
- break;
551
- }
552
- try {
553
- state.vdom.hooks?.$detach?.(target);
554
- } catch (err) {
555
- console.error(err);
528
+ if (!state) {
529
+ return;
530
+ }
531
+
532
+ const {vdom} = state;
533
+
534
+ if (vdom.hooks) {
535
+ reconcileListeners(target, EMPTY_MAP);
536
+ }
537
+
538
+ if (vdom.type === ELEMENT_NODE || vdom.type === OPAQUE_NODE) {
539
+ reconcileElementProps(target, EMPTY_MAP);
540
+ }
541
+
542
+ if (vdom.type === ELEMENT_NODE || vdom.type === ALIAS_NODE) {
543
+ cleanupTargetChildren(target);
544
+ }
545
+
546
+ delete target[NODE_STATE];
547
+
548
+ try {
549
+ if (vdom.type === SPECIAL_NODE) {
550
+ vdom.tag.detach?.(target);
556
551
  }
552
+ vdom.hooks?.$detach?.(target);
553
+ } catch (err) {
554
+ console.error(err);
557
555
  }
558
556
  }
559
557
 
@@ -581,17 +579,17 @@ export default userSettings => {
581
579
 
582
580
  let oldNodesPoolForTag = oldVNodeNodesPool.get(vdom.tag);
583
581
  if (!oldNodesPoolForTag) {
584
- oldNodesPoolForTag = {nodesForKey: new Map(), nodesWithoutKey: []};
582
+ oldNodesPoolForTag = {nodesForKey: newMap({}), nodesWithoutKey: []};
585
583
  oldVNodeNodesPool.set(vdom.tag, oldNodesPoolForTag);
586
584
  }
587
585
 
588
- if (vdom.key !== undefined) {
589
- let oldNodesPoolForKey = oldNodesPoolForTag.nodesForKey.get(vdom.key);
586
+ if (vdom.k !== undefined) {
587
+ let oldNodesPoolForKey = mapGet(oldNodesPoolForTag.nodesForKey, vdom.k);
590
588
  if (oldNodesPoolForKey === undefined) {
591
589
  oldNodesPoolForKey = [];
592
- oldNodesPoolForTag.nodesForKey.set(vdom.key, oldNodesPoolForKey);
593
590
  }
594
591
  oldNodesPoolForKey.push(oldChild);
592
+ oldNodesPoolForTag.nodesForKey = mapPut(oldNodesPoolForTag.nodesForKey, vdom.k, oldNodesPoolForKey);
595
593
  } else {
596
594
  oldNodesPoolForTag.nodesWithoutKey.push(oldChild);
597
595
  }
@@ -605,15 +603,15 @@ export default userSettings => {
605
603
  if (!oldNodesPoolForTag) {
606
604
  newDomNode = createNode(target, newVdom);
607
605
  } else {
608
- const key = newVdom.key;
606
+ const key = newVdom.k;
609
607
  if (key !== undefined) {
610
- const pool = oldNodesPoolForTag.nodesForKey.get(key);
608
+ const pool = mapGet(oldNodesPoolForTag.nodesForKey, key);
611
609
  if (pool && pool.length > 0) {
612
610
  newDomNode = pool.shift();
613
611
  const state = newDomNode[NODE_STATE];
614
612
  if (shouldUpdate(state.vdom.args, newVdom.args)) {
615
613
  if (state.vdom.hooks || newVdom.hooks) {
616
- reconcileListeners(target, newVdom.hooks);
614
+ reconcileListeners(newDomNode, newVdom.hooks);
617
615
  }
618
616
  state.newVdom = newVdom;
619
617
  }
@@ -627,7 +625,7 @@ export default userSettings => {
627
625
  const state = newDomNode[NODE_STATE];
628
626
  if (shouldUpdate(state.vdom.args, newVdom.args)) {
629
627
  if (state.vdom.hooks || newVdom.hooks) {
630
- reconcileListeners(target, newVdom.hooks);
628
+ reconcileListeners(newDomNode, newVdom.hooks);
631
629
  }
632
630
  state.newVdom = newVdom;
633
631
  }