@3sln/dodo 0.0.1 → 0.0.2

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 +22 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3sln/dodo",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A minimal, configurable virtual DOM library.",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/vdom.js CHANGED
@@ -448,21 +448,34 @@ export default (userSettings) => {
448
448
  return domNode;
449
449
  }
450
450
 
451
- function cleanupTarget(target) {
451
+ function cleanupTargetChildren(target) {
452
452
  if (target.children) {
453
453
  for (const child of target.children) {
454
454
  cleanupTarget(child);
455
455
  }
456
456
  }
457
+ }
457
458
 
459
+ function cleanupTarget(target) {
458
460
  const state = target[NODE_STATE];
459
461
  if (state) {
462
+
460
463
  switch (state.vdom.type) {
461
464
  case ELEMENT_NODE:
465
+ reconcileElementProps(target, {});
466
+ cleanupTargetChildren(target);
467
+ delete target[NODE_STATE];
468
+ break;
462
469
  case OPAQUE_NODE:
463
470
  reconcileElementProps(target, {});
471
+ delete target[NODE_STATE];
472
+ break;
473
+ case ALIAS_NODE:
474
+ cleanupTargetChildren(target);
475
+ delete target[NODE_STATE];
464
476
  break;
465
477
  case SPECIAL_NODE:
478
+ delete target[NODE_STATE];
466
479
  try {
467
480
  state.vdom.tag.detach?.(target);
468
481
  } catch (err) {
@@ -475,7 +488,6 @@ export default (userSettings) => {
475
488
  } catch (err) {
476
489
  console.error(err);
477
490
  }
478
- delete target[NODE_STATE];
479
491
  }
480
492
  }
481
493
 
@@ -620,8 +632,14 @@ export default (userSettings) => {
620
632
  }
621
633
 
622
634
  function reconcile(target, vdom) {
635
+ const state = target[NODE_STATE];
623
636
  if (vdom === null || vdom === undefined) {
624
- cleanupTarget(target);
637
+ if (state) {
638
+ cleanupTarget(target);
639
+ } else {
640
+ cleanupTargetChildren(target);
641
+ }
642
+ target.replaceChildren();
625
643
  return;
626
644
  }
627
645
 
@@ -631,7 +649,6 @@ export default (userSettings) => {
631
649
  }
632
650
 
633
651
  if (vdom instanceof VNode) {
634
- let state = target[NODE_STATE];
635
652
  if (state) {
636
653
  if (state.vdom.type === vdom.type) {
637
654
  if (shouldUpdate(state.vdom.args, vdom.args)) {
@@ -652,7 +669,7 @@ export default (userSettings) => {
652
669
  break;
653
670
  }
654
671
 
655
- target[NODE_STATE] = state = { originalProps: {}, newVdom: vdom };
672
+ target[NODE_STATE] = { originalProps: {}, newVdom: vdom };
656
673
  try {
657
674
  vdom.hooks?.$attach?.(target);
658
675
  if (vdom.type === SPECIAL_NODE) {