@tarojs/runtime 3.7.0-alpha.4 → 3.7.0-alpha.6
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/dist/runtime.cjs.d.ts +1 -0
- package/dist/runtime.cjs.js +38 -4
- package/dist/runtime.esm.d.ts +1 -0
- package/dist/runtime.esm.js +36 -4
- package/dist/runtime.esm.js.map +1 -1
- package/dist/runtime.h5.d.ts +1 -0
- package/dist/runtime.h5.js +36 -4
- package/package.json +2 -2
package/dist/runtime.h5.d.ts
CHANGED
|
@@ -221,6 +221,7 @@ declare class TaroNode extends TaroEventTarget {
|
|
|
221
221
|
constructor();
|
|
222
222
|
private hydrate;
|
|
223
223
|
private updateChildNodes;
|
|
224
|
+
private updateSingleChild;
|
|
224
225
|
get _root(): TaroRootElement | null;
|
|
225
226
|
protected findIndex(refChild: TaroNode): number;
|
|
226
227
|
get _path(): string;
|
package/dist/runtime.h5.js
CHANGED
|
@@ -519,6 +519,18 @@ class TaroNode extends TaroEventTarget {
|
|
|
519
519
|
value: isClean ? cleanChildNodes : rerenderChildNodes
|
|
520
520
|
});
|
|
521
521
|
}
|
|
522
|
+
updateSingleChild(index) {
|
|
523
|
+
this.childNodes.forEach((child, childIndex) => {
|
|
524
|
+
if (isComment(child))
|
|
525
|
+
return;
|
|
526
|
+
if (index && childIndex < index)
|
|
527
|
+
return;
|
|
528
|
+
this.enqueueUpdate({
|
|
529
|
+
path: child._path,
|
|
530
|
+
value: this.hydrate(child)
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
}
|
|
522
534
|
get _root() {
|
|
523
535
|
var _a;
|
|
524
536
|
return ((_a = this.parentNode) === null || _a === void 0 ? void 0 : _a._root) || null;
|
|
@@ -610,22 +622,24 @@ class TaroNode extends TaroEventTarget {
|
|
|
610
622
|
// - cleanRef: false (No need to clean eventSource, because newChild is about to be inserted)
|
|
611
623
|
// - update: true (Need to update parent.childNodes, because parent.childNodes is reordered)
|
|
612
624
|
newChild.remove({ cleanRef: false });
|
|
625
|
+
let index = 0;
|
|
613
626
|
// Data structure
|
|
614
627
|
newChild.parentNode = this;
|
|
615
628
|
if (refChild) {
|
|
616
629
|
// insertBefore & replaceChild
|
|
617
|
-
|
|
630
|
+
index = this.findIndex(refChild);
|
|
618
631
|
this.childNodes.splice(index, 0, newChild);
|
|
619
632
|
}
|
|
620
633
|
else {
|
|
621
634
|
// appendChild
|
|
622
635
|
this.childNodes.push(newChild);
|
|
623
636
|
}
|
|
637
|
+
const childNodesLength = this.childNodes.length;
|
|
624
638
|
// Serialization
|
|
625
639
|
if (this._root) {
|
|
626
640
|
if (!refChild) {
|
|
627
641
|
// appendChild
|
|
628
|
-
const isOnlyChild =
|
|
642
|
+
const isOnlyChild = childNodesLength === 1;
|
|
629
643
|
if (isOnlyChild) {
|
|
630
644
|
this.updateChildNodes();
|
|
631
645
|
}
|
|
@@ -644,8 +658,26 @@ class TaroNode extends TaroEventTarget {
|
|
|
644
658
|
});
|
|
645
659
|
}
|
|
646
660
|
else {
|
|
647
|
-
// insertBefore
|
|
648
|
-
|
|
661
|
+
// insertBefore 有两种更新模式
|
|
662
|
+
// 比方说有 A B C 三个节点,现在要在 C 前插入 D
|
|
663
|
+
// 1. 插入 D,然后更新整个父节点的 childNodes 数组
|
|
664
|
+
// setData({ cn: [A, B, D, C] })
|
|
665
|
+
// 2. 插入 D,然后更新 D 以及 D 之后每个节点的数据
|
|
666
|
+
// setData ({
|
|
667
|
+
// cn.[2]: D,
|
|
668
|
+
// cn.[3]: C,
|
|
669
|
+
// })
|
|
670
|
+
// 由于微信解析 ’cn.[2]‘ 这些路径的时候也需要消耗时间,
|
|
671
|
+
// 所以根据 insertBefore 插入的位置来做不同的处理
|
|
672
|
+
const mark = childNodesLength * 2 / 3;
|
|
673
|
+
if (mark > index) {
|
|
674
|
+
// 如果 insertBefore 的位置在 childNodes 的 2/3 前,则为了避免解析路径消耗过多的时间,采用第一种方式
|
|
675
|
+
this.updateChildNodes();
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
// 如果 insertBefore 的位置在 childNodes 的 2/3 之后,则采用第二种方式,避免 childNodes 的全量更新
|
|
679
|
+
this.updateSingleChild(index);
|
|
680
|
+
}
|
|
649
681
|
}
|
|
650
682
|
}
|
|
651
683
|
MutationObserver.record({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/runtime",
|
|
3
|
-
"version": "3.7.0-alpha.
|
|
3
|
+
"version": "3.7.0-alpha.6",
|
|
4
4
|
"description": "taro runtime for mini apps.",
|
|
5
5
|
"main:h5": "dist/runtime.h5.js",
|
|
6
6
|
"main": "dist/runtime.esm.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"lodash-es": "4.17.21",
|
|
23
|
-
"@tarojs/shared": "3.7.0-alpha.
|
|
23
|
+
"@tarojs/shared": "3.7.0-alpha.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@rollup/plugin-buble": "^0.21.3",
|