@3sln/dodo 0.0.6 → 0.0.8

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 +41 -41
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3sln/dodo",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
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
 
@@ -395,7 +395,8 @@ export default userSettings => {
395
395
  }
396
396
  } else {
397
397
  const oldHooks = state.vdom.hooks ?? EMPTY_MAP;
398
- const hooksIterator = toIterator(mapIter(hooks));
398
+ const newHooks = hooks ?? EMPTY_MAP;
399
+ const hooksIterator = toIterator(mapIter(newHooks));
399
400
  let result;
400
401
  while (!(result = hooksIterator.next()).done) {
401
402
  const [name, listener] = result.value;
@@ -427,7 +428,7 @@ export default userSettings => {
427
428
  while (!(result = oldHooksIterator.next()).done) {
428
429
  const [name] = result.value;
429
430
  const hookName = convertHookName(name);
430
- if (hookName[0] === '$' || mapGet(hooks, name) !== undefined) continue;
431
+ if (hookName[0] === '$' || mapGet(newHooks, name) !== undefined) continue;
431
432
  const oldListener = mapGet(oldHooks, name);
432
433
  if (typeof oldListener === 'function') {
433
434
  target.removeEventListener(hookName, oldListener);
@@ -462,7 +463,7 @@ export default userSettings => {
462
463
  const innerVdom = newVdom.tag.apply(undefined, newVdom.args);
463
464
  if (innerVdom === undefined || innerVdom === null) break;
464
465
  if (isSeq(innerVdom)) {
465
- reconcileElementChildren(target, flattenSeq(innerVdom));
466
+ reconcileElementChildren(target, flattenSeq(innerVdom, true));
466
467
  } else {
467
468
  reconcileElementChildren(target, flattenVNodeChildren([innerVdom]));
468
469
  }
@@ -525,35 +526,33 @@ export default userSettings => {
525
526
 
526
527
  function cleanupTarget(target) {
527
528
  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);
529
+ if (!state) {
530
+ return;
531
+ }
532
+
533
+ const {vdom} = state;
534
+
535
+ if (vdom.hooks) {
536
+ reconcileListeners(target, EMPTY_MAP);
537
+ }
538
+
539
+ if (vdom.type === ELEMENT_NODE || vdom.type === OPAQUE_NODE) {
540
+ reconcileElementProps(target, EMPTY_MAP);
541
+ }
542
+
543
+ if (vdom.type === ELEMENT_NODE || vdom.type === ALIAS_NODE) {
544
+ cleanupTargetChildren(target);
545
+ }
546
+
547
+ delete target[NODE_STATE];
548
+
549
+ try {
550
+ if (vdom.type === SPECIAL_NODE) {
551
+ vdom.tag.detach?.(target);
556
552
  }
553
+ vdom.hooks?.$detach?.(target);
554
+ } catch (err) {
555
+ console.error(err);
557
556
  }
558
557
  }
559
558
 
@@ -581,17 +580,17 @@ export default userSettings => {
581
580
 
582
581
  let oldNodesPoolForTag = oldVNodeNodesPool.get(vdom.tag);
583
582
  if (!oldNodesPoolForTag) {
584
- oldNodesPoolForTag = {nodesForKey: new Map(), nodesWithoutKey: []};
583
+ oldNodesPoolForTag = {nodesForKey: newMap({}), nodesWithoutKey: []};
585
584
  oldVNodeNodesPool.set(vdom.tag, oldNodesPoolForTag);
586
585
  }
587
586
 
588
- if (vdom.key !== undefined) {
589
- let oldNodesPoolForKey = oldNodesPoolForTag.nodesForKey.get(vdom.key);
587
+ if (vdom.k !== undefined) {
588
+ let oldNodesPoolForKey = mapGet(oldNodesPoolForTag.nodesForKey, vdom.k);
590
589
  if (oldNodesPoolForKey === undefined) {
591
590
  oldNodesPoolForKey = [];
592
- oldNodesPoolForTag.nodesForKey.set(vdom.key, oldNodesPoolForKey);
593
591
  }
594
592
  oldNodesPoolForKey.push(oldChild);
593
+ oldNodesPoolForTag.nodesForKey = mapPut(oldNodesPoolForTag.nodesForKey, vdom.k, oldNodesPoolForKey);
595
594
  } else {
596
595
  oldNodesPoolForTag.nodesWithoutKey.push(oldChild);
597
596
  }
@@ -605,15 +604,15 @@ export default userSettings => {
605
604
  if (!oldNodesPoolForTag) {
606
605
  newDomNode = createNode(target, newVdom);
607
606
  } else {
608
- const key = newVdom.key;
607
+ const key = newVdom.k;
609
608
  if (key !== undefined) {
610
- const pool = oldNodesPoolForTag.nodesForKey.get(key);
609
+ const pool = mapGet(oldNodesPoolForTag.nodesForKey, key);
611
610
  if (pool && pool.length > 0) {
612
611
  newDomNode = pool.shift();
613
612
  const state = newDomNode[NODE_STATE];
614
613
  if (shouldUpdate(state.vdom.args, newVdom.args)) {
615
614
  if (state.vdom.hooks || newVdom.hooks) {
616
- reconcileListeners(target, newVdom.hooks);
615
+ reconcileListeners(newDomNode, newVdom.hooks);
617
616
  }
618
617
  state.newVdom = newVdom;
619
618
  }
@@ -627,7 +626,7 @@ export default userSettings => {
627
626
  const state = newDomNode[NODE_STATE];
628
627
  if (shouldUpdate(state.vdom.args, newVdom.args)) {
629
628
  if (state.vdom.hooks || newVdom.hooks) {
630
- reconcileListeners(target, newVdom.hooks);
629
+ reconcileListeners(newDomNode, newVdom.hooks);
631
630
  }
632
631
  state.newVdom = newVdom;
633
632
  }
@@ -653,6 +652,7 @@ export default userSettings => {
653
652
  target.removeChild(nodeToRemove);
654
653
  }
655
654
 
655
+ const window = userSettings?.window ?? target.ownerDocument.defaultView;
656
656
  const moveBefore = window.Element.prototype.moveBefore;
657
657
  const insertBefore = window.Element.prototype.insertBefore;
658
658
  if (target.isConnected) {
@@ -750,7 +750,7 @@ export default userSettings => {
750
750
  }
751
751
 
752
752
  if (isSeq(vdom)) {
753
- reconcileElementChildren(target, flattenSeq(vdom));
753
+ reconcileElementChildren(target, flattenSeq(vdom, true));
754
754
  return;
755
755
  }
756
756