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
|
@@ -1682,6 +1682,44 @@ class Interpreter {
|
|
|
1682
1682
|
node.realAfter = this.insertAfterAnchor('context-after');
|
|
1683
1683
|
return node;
|
|
1684
1684
|
}
|
|
1685
|
+
formatForCollection(collection) {
|
|
1686
|
+
const res = {
|
|
1687
|
+
arr: [],
|
|
1688
|
+
keys: null
|
|
1689
|
+
};
|
|
1690
|
+
if (Array.isArray(collection)) {
|
|
1691
|
+
res.arr = collection;
|
|
1692
|
+
return res;
|
|
1693
|
+
}
|
|
1694
|
+
if (collection instanceof Map) {
|
|
1695
|
+
res.keys = [];
|
|
1696
|
+
collection.forEach((v, k) => {
|
|
1697
|
+
res.arr.push(v);
|
|
1698
|
+
res.keys.push(k);
|
|
1699
|
+
});
|
|
1700
|
+
return res;
|
|
1701
|
+
}
|
|
1702
|
+
if (typeof collection === 'object' && collection !== null) {
|
|
1703
|
+
if (collection[Symbol.iterator]) {
|
|
1704
|
+
res.arr = Array.from(collection);
|
|
1705
|
+
return res;
|
|
1706
|
+
}
|
|
1707
|
+
res.arr = Object.values(collection);
|
|
1708
|
+
res.keys = Object.keys(collection);
|
|
1709
|
+
return res;
|
|
1710
|
+
}
|
|
1711
|
+
if (typeof collection === 'number') {
|
|
1712
|
+
res.arr = Array.from({
|
|
1713
|
+
length: collection
|
|
1714
|
+
});
|
|
1715
|
+
return res;
|
|
1716
|
+
}
|
|
1717
|
+
if (typeof collection === 'string') {
|
|
1718
|
+
res.arr = collection.split('');
|
|
1719
|
+
return res;
|
|
1720
|
+
}
|
|
1721
|
+
return res;
|
|
1722
|
+
}
|
|
1685
1723
|
forDeclaration() {
|
|
1686
1724
|
const arrExp = this.tokenizer.jsExp().value;
|
|
1687
1725
|
this.tokenizer.nextToken();
|
|
@@ -1718,6 +1756,8 @@ class Interpreter {
|
|
|
1718
1756
|
realBefore: prevSibling?.realAfter || prevSibling,
|
|
1719
1757
|
realAfter: null,
|
|
1720
1758
|
arr: null,
|
|
1759
|
+
reactiveArr: null,
|
|
1760
|
+
keys: null,
|
|
1721
1761
|
arrSignal: null,
|
|
1722
1762
|
itemExp,
|
|
1723
1763
|
indexName,
|
|
@@ -1744,11 +1784,17 @@ class Interpreter {
|
|
|
1744
1784
|
const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
|
|
1745
1785
|
let isFirstRender = true;
|
|
1746
1786
|
forNode.effect = new this.Effect(() => {
|
|
1747
|
-
|
|
1787
|
+
const collection = arrSignal.get();
|
|
1788
|
+
const _this$formatForCollec = this.formatForCollection(collection),
|
|
1789
|
+
formattedArr = _this$formatForCollec.arr,
|
|
1790
|
+
keys = _this$formatForCollec.keys;
|
|
1791
|
+
let arr = formattedArr;
|
|
1748
1792
|
arr[Keys.Iterator];
|
|
1749
1793
|
const prevCtx = getPulling();
|
|
1750
1794
|
setPulling(null);
|
|
1751
|
-
forNode.
|
|
1795
|
+
forNode.reactiveArr = formattedArr;
|
|
1796
|
+
forNode.arr = Array.isArray(collection) ? toRaw(arr) : arr;
|
|
1797
|
+
forNode.keys = keys;
|
|
1752
1798
|
const children = forNode.children;
|
|
1753
1799
|
if (isFirstRender) {
|
|
1754
1800
|
const len = arr.length;
|
|
@@ -1786,7 +1832,7 @@ class Interpreter {
|
|
|
1786
1832
|
for (let i = minLen; i--;) {
|
|
1787
1833
|
const child = children[i];
|
|
1788
1834
|
newChildren[i] = child;
|
|
1789
|
-
this.reuseForItem(child, arr[i], itemExp, i, indexName);
|
|
1835
|
+
this.reuseForItem(child, arr[i], itemExp, i, indexName, keys?.[i]);
|
|
1790
1836
|
}
|
|
1791
1837
|
} else {
|
|
1792
1838
|
let s = 0,
|
|
@@ -1799,7 +1845,7 @@ class Interpreter {
|
|
|
1799
1845
|
const key = forNode.getKey(itemData);
|
|
1800
1846
|
if (old === key) {
|
|
1801
1847
|
newChildren[s] = child;
|
|
1802
|
-
this.reuseForItem(child, arr[s], itemExp, s, indexName);
|
|
1848
|
+
this.reuseForItem(child, arr[s], itemExp, s, indexName, keys?.[s]);
|
|
1803
1849
|
s++;
|
|
1804
1850
|
} else {
|
|
1805
1851
|
break;
|
|
@@ -1812,7 +1858,7 @@ class Interpreter {
|
|
|
1812
1858
|
const key = forNode.getKey(itemData);
|
|
1813
1859
|
if (old === key) {
|
|
1814
1860
|
newChildren[e2] = child;
|
|
1815
|
-
this.reuseForItem(child, arr[e2], itemExp, e2, indexName);
|
|
1861
|
+
this.reuseForItem(child, arr[e2], itemExp, e2, indexName, keys?.[e2]);
|
|
1816
1862
|
e1--;
|
|
1817
1863
|
e2--;
|
|
1818
1864
|
} else {
|
|
@@ -1854,7 +1900,7 @@ class Interpreter {
|
|
|
1854
1900
|
}
|
|
1855
1901
|
const child = children[i];
|
|
1856
1902
|
newChildren[newI] = child;
|
|
1857
|
-
this.reuseForItem(child, arr[newI], itemExp, newI, indexName);
|
|
1903
|
+
this.reuseForItem(child, arr[newI], itemExp, newI, indexName, keys?.[newI]);
|
|
1858
1904
|
new2oldI[newI - s2] = i;
|
|
1859
1905
|
key2new.delete(key);
|
|
1860
1906
|
if (newI < maxIncNewI) {
|
|
@@ -1940,15 +1986,15 @@ class Interpreter {
|
|
|
1940
1986
|
this.remove(child.realAfter);
|
|
1941
1987
|
child.effect.dispose();
|
|
1942
1988
|
}
|
|
1943
|
-
reuseForItem(child, data, itemExp, i, indexName) {
|
|
1989
|
+
reuseForItem(child, data, itemExp, i, indexName, indexValue) {
|
|
1944
1990
|
if (typeof itemExp === 'string') {
|
|
1945
1991
|
child.data[itemExp] = data;
|
|
1946
1992
|
if (indexName) {
|
|
1947
|
-
child.data[indexName] = i;
|
|
1993
|
+
child.data[indexName] = indexValue ?? i;
|
|
1948
1994
|
}
|
|
1949
1995
|
} else {
|
|
1950
1996
|
indexName = indexName || KEY_INDEX;
|
|
1951
|
-
child.data[indexName] = i;
|
|
1997
|
+
child.data[indexName] = indexValue ?? i;
|
|
1952
1998
|
}
|
|
1953
1999
|
}
|
|
1954
2000
|
forItemId = 0;
|
|
@@ -1982,23 +2028,24 @@ class Interpreter {
|
|
|
1982
2028
|
itemExp = forNode.itemExp,
|
|
1983
2029
|
vars = forNode.vars,
|
|
1984
2030
|
arrSignal = forNode.arrSignal,
|
|
1985
|
-
getKey = forNode.getKey
|
|
2031
|
+
getKey = forNode.getKey,
|
|
2032
|
+
keys = forNode.keys;
|
|
1986
2033
|
let indexName = forNode.indexName;
|
|
1987
2034
|
let data;
|
|
1988
2035
|
if (typeof itemExp === 'string') {
|
|
1989
2036
|
data = deepSignal(indexName ? {
|
|
1990
2037
|
[itemExp]: arr[i],
|
|
1991
|
-
[indexName]: i
|
|
2038
|
+
[indexName]: keys?.[i] ?? i
|
|
1992
2039
|
} : {
|
|
1993
2040
|
[itemExp]: arr[i]
|
|
1994
2041
|
}, getPulling());
|
|
1995
2042
|
} else {
|
|
1996
2043
|
indexName = indexName ?? KEY_INDEX;
|
|
1997
2044
|
const rawData = {
|
|
1998
|
-
[indexName]: i
|
|
2045
|
+
[indexName]: keys?.[i] ?? i
|
|
1999
2046
|
};
|
|
2000
2047
|
data = deepSignal(rawData, getPulling());
|
|
2001
|
-
const computedData = new Computed(() => itemExp(arrSignal.get()[getKey ? data[indexName] : i]));
|
|
2048
|
+
const computedData = new Computed(() => itemExp((arrSignal.get(), forNode.reactiveArr)[getKey ? data[indexName] : keys ? (data[indexName], i) : i]));
|
|
2002
2049
|
const cells = data[Keys.Meta].cells;
|
|
2003
2050
|
for (let i = 0; i < vars.length; i++) {
|
|
2004
2051
|
const name = vars[i];
|