@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.
- package/package.json +1 -1
- package/src/vdom.js +41 -41
package/package.json
CHANGED
package/src/vdom.js
CHANGED
|
@@ -13,7 +13,7 @@ class VNode {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
key(k) {
|
|
16
|
-
this.
|
|
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
|
|
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(
|
|
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
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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:
|
|
583
|
+
oldNodesPoolForTag = {nodesForKey: newMap({}), nodesWithoutKey: []};
|
|
585
584
|
oldVNodeNodesPool.set(vdom.tag, oldNodesPoolForTag);
|
|
586
585
|
}
|
|
587
586
|
|
|
588
|
-
if (vdom.
|
|
589
|
-
let oldNodesPoolForKey = oldNodesPoolForTag.nodesForKey
|
|
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.
|
|
607
|
+
const key = newVdom.k;
|
|
609
608
|
if (key !== undefined) {
|
|
610
|
-
const pool = oldNodesPoolForTag.nodesForKey
|
|
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(
|
|
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(
|
|
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
|
|