bobe 0.0.53 → 0.0.54
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/bobe.cjs.js +60 -13
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +60 -13
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +60 -13
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +60 -13
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.umd.js +60 -13
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -31,10 +31,16 @@ declare class Interpreter {
|
|
|
31
31
|
* */
|
|
32
32
|
declaration(ctx: ProgramCtx): any;
|
|
33
33
|
createContextNode(): ContextNode;
|
|
34
|
+
formatForCollection(collection: any): {
|
|
35
|
+
arr: any[];
|
|
36
|
+
keys: string[] | null;
|
|
37
|
+
};
|
|
34
38
|
forDeclaration(): ForNode | ForItemNode;
|
|
35
39
|
insertForItem(forNode: ForNode, i: number, parentData: any, newChildren: ForItemNode[], before: any, snapshotForUpdate: any): void;
|
|
36
40
|
removeForItem(children: ForItemNode[], i: number): void;
|
|
37
|
-
reuseForItem(child: ForItemNode, data: any, itemExp: string | ((value: any) => any), i: number, indexName?: string
|
|
41
|
+
reuseForItem(child: ForItemNode, data: any, itemExp: string | ((value: any) => any), i: number, indexName?: string,
|
|
42
|
+
/** Map/Set 等有 key 时,index 值为 key */
|
|
43
|
+
indexValue?: any): void;
|
|
38
44
|
forItemId: number;
|
|
39
45
|
createForItem(forNode: ForNode, i: number, parentData: any): ForItemNode;
|
|
40
46
|
getItemData(forNode: ForNode, i: number, parentData: any): Record<any, any>;
|
|
@@ -258,6 +264,9 @@ type ForNode = Omit<LogicNode, 'data'> & {
|
|
|
258
264
|
indexName?: string;
|
|
259
265
|
getKey?: (data: any) => any;
|
|
260
266
|
arr: any[];
|
|
267
|
+
/** 响应式版本:数组为 proxy、Map/Set 的 item 已被 deepSignal 包装 */
|
|
268
|
+
reactiveArr: any[];
|
|
269
|
+
keys: string[] | null;
|
|
261
270
|
arrSignal: Signal<any[]> | Computed<any[]>;
|
|
262
271
|
effect: Effect;
|
|
263
272
|
i: number;
|
package/dist/index.umd.js
CHANGED
|
@@ -1657,6 +1657,44 @@
|
|
|
1657
1657
|
node.realAfter = this.insertAfterAnchor('context-after');
|
|
1658
1658
|
return node;
|
|
1659
1659
|
}
|
|
1660
|
+
formatForCollection(collection) {
|
|
1661
|
+
const res = {
|
|
1662
|
+
arr: [],
|
|
1663
|
+
keys: null
|
|
1664
|
+
};
|
|
1665
|
+
if (Array.isArray(collection)) {
|
|
1666
|
+
res.arr = collection;
|
|
1667
|
+
return res;
|
|
1668
|
+
}
|
|
1669
|
+
if (collection instanceof Map) {
|
|
1670
|
+
res.keys = [];
|
|
1671
|
+
collection.forEach((v, k) => {
|
|
1672
|
+
res.arr.push(v);
|
|
1673
|
+
res.keys.push(k);
|
|
1674
|
+
});
|
|
1675
|
+
return res;
|
|
1676
|
+
}
|
|
1677
|
+
if (typeof collection === 'object' && collection !== null) {
|
|
1678
|
+
if (collection[Symbol.iterator]) {
|
|
1679
|
+
res.arr = Array.from(collection);
|
|
1680
|
+
return res;
|
|
1681
|
+
}
|
|
1682
|
+
res.arr = Object.values(collection);
|
|
1683
|
+
res.keys = Object.keys(collection);
|
|
1684
|
+
return res;
|
|
1685
|
+
}
|
|
1686
|
+
if (typeof collection === 'number') {
|
|
1687
|
+
res.arr = Array.from({
|
|
1688
|
+
length: collection
|
|
1689
|
+
});
|
|
1690
|
+
return res;
|
|
1691
|
+
}
|
|
1692
|
+
if (typeof collection === 'string') {
|
|
1693
|
+
res.arr = collection.split('');
|
|
1694
|
+
return res;
|
|
1695
|
+
}
|
|
1696
|
+
return res;
|
|
1697
|
+
}
|
|
1660
1698
|
forDeclaration() {
|
|
1661
1699
|
const arrExp = this.tokenizer.jsExp().value;
|
|
1662
1700
|
this.tokenizer.nextToken();
|
|
@@ -1693,6 +1731,8 @@
|
|
|
1693
1731
|
realBefore: prevSibling?.realAfter || prevSibling,
|
|
1694
1732
|
realAfter: null,
|
|
1695
1733
|
arr: null,
|
|
1734
|
+
reactiveArr: null,
|
|
1735
|
+
keys: null,
|
|
1696
1736
|
arrSignal: null,
|
|
1697
1737
|
itemExp,
|
|
1698
1738
|
indexName,
|
|
@@ -1719,11 +1759,17 @@
|
|
|
1719
1759
|
const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
|
|
1720
1760
|
let isFirstRender = true;
|
|
1721
1761
|
forNode.effect = new this.Effect(() => {
|
|
1722
|
-
|
|
1762
|
+
const collection = arrSignal.get();
|
|
1763
|
+
const _this$formatForCollec = this.formatForCollection(collection),
|
|
1764
|
+
formattedArr = _this$formatForCollec.arr,
|
|
1765
|
+
keys = _this$formatForCollec.keys;
|
|
1766
|
+
let arr = formattedArr;
|
|
1723
1767
|
arr[aoye.Keys.Iterator];
|
|
1724
1768
|
const prevCtx = aoye.getPulling();
|
|
1725
1769
|
aoye.setPulling(null);
|
|
1726
|
-
forNode.
|
|
1770
|
+
forNode.reactiveArr = formattedArr;
|
|
1771
|
+
forNode.arr = Array.isArray(collection) ? aoye.toRaw(arr) : arr;
|
|
1772
|
+
forNode.keys = keys;
|
|
1727
1773
|
const children = forNode.children;
|
|
1728
1774
|
if (isFirstRender) {
|
|
1729
1775
|
const len = arr.length;
|
|
@@ -1761,7 +1807,7 @@
|
|
|
1761
1807
|
for (let i = minLen; i--;) {
|
|
1762
1808
|
const child = children[i];
|
|
1763
1809
|
newChildren[i] = child;
|
|
1764
|
-
this.reuseForItem(child, arr[i], itemExp, i, indexName);
|
|
1810
|
+
this.reuseForItem(child, arr[i], itemExp, i, indexName, keys?.[i]);
|
|
1765
1811
|
}
|
|
1766
1812
|
} else {
|
|
1767
1813
|
let s = 0,
|
|
@@ -1774,7 +1820,7 @@
|
|
|
1774
1820
|
const key = forNode.getKey(itemData);
|
|
1775
1821
|
if (old === key) {
|
|
1776
1822
|
newChildren[s] = child;
|
|
1777
|
-
this.reuseForItem(child, arr[s], itemExp, s, indexName);
|
|
1823
|
+
this.reuseForItem(child, arr[s], itemExp, s, indexName, keys?.[s]);
|
|
1778
1824
|
s++;
|
|
1779
1825
|
} else {
|
|
1780
1826
|
break;
|
|
@@ -1787,7 +1833,7 @@
|
|
|
1787
1833
|
const key = forNode.getKey(itemData);
|
|
1788
1834
|
if (old === key) {
|
|
1789
1835
|
newChildren[e2] = child;
|
|
1790
|
-
this.reuseForItem(child, arr[e2], itemExp, e2, indexName);
|
|
1836
|
+
this.reuseForItem(child, arr[e2], itemExp, e2, indexName, keys?.[e2]);
|
|
1791
1837
|
e1--;
|
|
1792
1838
|
e2--;
|
|
1793
1839
|
} else {
|
|
@@ -1829,7 +1875,7 @@
|
|
|
1829
1875
|
}
|
|
1830
1876
|
const child = children[i];
|
|
1831
1877
|
newChildren[newI] = child;
|
|
1832
|
-
this.reuseForItem(child, arr[newI], itemExp, newI, indexName);
|
|
1878
|
+
this.reuseForItem(child, arr[newI], itemExp, newI, indexName, keys?.[newI]);
|
|
1833
1879
|
new2oldI[newI - s2] = i;
|
|
1834
1880
|
key2new.delete(key);
|
|
1835
1881
|
if (newI < maxIncNewI) {
|
|
@@ -1915,15 +1961,15 @@
|
|
|
1915
1961
|
this.remove(child.realAfter);
|
|
1916
1962
|
child.effect.dispose();
|
|
1917
1963
|
}
|
|
1918
|
-
reuseForItem(child, data, itemExp, i, indexName) {
|
|
1964
|
+
reuseForItem(child, data, itemExp, i, indexName, indexValue) {
|
|
1919
1965
|
if (typeof itemExp === 'string') {
|
|
1920
1966
|
child.data[itemExp] = data;
|
|
1921
1967
|
if (indexName) {
|
|
1922
|
-
child.data[indexName] = i;
|
|
1968
|
+
child.data[indexName] = indexValue ?? i;
|
|
1923
1969
|
}
|
|
1924
1970
|
} else {
|
|
1925
1971
|
indexName = indexName || KEY_INDEX;
|
|
1926
|
-
child.data[indexName] = i;
|
|
1972
|
+
child.data[indexName] = indexValue ?? i;
|
|
1927
1973
|
}
|
|
1928
1974
|
}
|
|
1929
1975
|
forItemId = 0;
|
|
@@ -1957,23 +2003,24 @@
|
|
|
1957
2003
|
itemExp = forNode.itemExp,
|
|
1958
2004
|
vars = forNode.vars,
|
|
1959
2005
|
arrSignal = forNode.arrSignal,
|
|
1960
|
-
getKey = forNode.getKey
|
|
2006
|
+
getKey = forNode.getKey,
|
|
2007
|
+
keys = forNode.keys;
|
|
1961
2008
|
let indexName = forNode.indexName;
|
|
1962
2009
|
let data;
|
|
1963
2010
|
if (typeof itemExp === 'string') {
|
|
1964
2011
|
data = aoye.deepSignal(indexName ? {
|
|
1965
2012
|
[itemExp]: arr[i],
|
|
1966
|
-
[indexName]: i
|
|
2013
|
+
[indexName]: keys?.[i] ?? i
|
|
1967
2014
|
} : {
|
|
1968
2015
|
[itemExp]: arr[i]
|
|
1969
2016
|
}, aoye.getPulling());
|
|
1970
2017
|
} else {
|
|
1971
2018
|
indexName = indexName ?? KEY_INDEX;
|
|
1972
2019
|
const rawData = {
|
|
1973
|
-
[indexName]: i
|
|
2020
|
+
[indexName]: keys?.[i] ?? i
|
|
1974
2021
|
};
|
|
1975
2022
|
data = aoye.deepSignal(rawData, aoye.getPulling());
|
|
1976
|
-
const computedData = new aoye.Computed(() => itemExp(arrSignal.get()[getKey ? data[indexName] : i]));
|
|
2023
|
+
const computedData = new aoye.Computed(() => itemExp((arrSignal.get(), forNode.reactiveArr)[getKey ? data[indexName] : keys ? (data[indexName], i) : i]));
|
|
1977
2024
|
const cells = data[aoye.Keys.Meta].cells;
|
|
1978
2025
|
for (let i = 0; i < vars.length; i++) {
|
|
1979
2026
|
const name = vars[i];
|