bobe 0.0.53 → 0.0.56
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 +63 -13
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +63 -13
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +64 -15
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +64 -15
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +15 -16
- package/dist/index.umd.js +63 -13
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
|
@@ -252,6 +252,7 @@ class Tokenizer {
|
|
|
252
252
|
}
|
|
253
253
|
isEof() {
|
|
254
254
|
if (!this.token) return false;
|
|
255
|
+
if (this.i >= this.code.length && !this.waitingTokens.len) return true;
|
|
255
256
|
return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
|
|
256
257
|
}
|
|
257
258
|
setToken(type, value, dt = 1) {
|
|
@@ -1683,6 +1684,44 @@ class Interpreter {
|
|
|
1683
1684
|
node.realAfter = this.insertAfterAnchor('context-after');
|
|
1684
1685
|
return node;
|
|
1685
1686
|
}
|
|
1687
|
+
formatForCollection(collection) {
|
|
1688
|
+
const res = {
|
|
1689
|
+
arr: [],
|
|
1690
|
+
keys: null
|
|
1691
|
+
};
|
|
1692
|
+
if (Array.isArray(collection)) {
|
|
1693
|
+
res.arr = collection;
|
|
1694
|
+
return res;
|
|
1695
|
+
}
|
|
1696
|
+
if (collection instanceof Map) {
|
|
1697
|
+
res.keys = [];
|
|
1698
|
+
collection.forEach((v, k) => {
|
|
1699
|
+
res.arr.push(v);
|
|
1700
|
+
res.keys.push(k);
|
|
1701
|
+
});
|
|
1702
|
+
return res;
|
|
1703
|
+
}
|
|
1704
|
+
if (typeof collection === 'object' && collection !== null) {
|
|
1705
|
+
if (collection[Symbol.iterator]) {
|
|
1706
|
+
res.arr = Array.from(collection);
|
|
1707
|
+
return res;
|
|
1708
|
+
}
|
|
1709
|
+
res.arr = Object.values(collection);
|
|
1710
|
+
res.keys = Object.keys(collection);
|
|
1711
|
+
return res;
|
|
1712
|
+
}
|
|
1713
|
+
if (typeof collection === 'number') {
|
|
1714
|
+
res.arr = Array.from({
|
|
1715
|
+
length: collection
|
|
1716
|
+
});
|
|
1717
|
+
return res;
|
|
1718
|
+
}
|
|
1719
|
+
if (typeof collection === 'string') {
|
|
1720
|
+
res.arr = collection.split('');
|
|
1721
|
+
return res;
|
|
1722
|
+
}
|
|
1723
|
+
return res;
|
|
1724
|
+
}
|
|
1686
1725
|
forDeclaration() {
|
|
1687
1726
|
const arrExp = this.tokenizer.jsExp().value;
|
|
1688
1727
|
this.tokenizer.nextToken();
|
|
@@ -1719,6 +1758,8 @@ class Interpreter {
|
|
|
1719
1758
|
realBefore: prevSibling?.realAfter || prevSibling,
|
|
1720
1759
|
realAfter: null,
|
|
1721
1760
|
arr: null,
|
|
1761
|
+
reactiveArr: null,
|
|
1762
|
+
keys: null,
|
|
1722
1763
|
arrSignal: null,
|
|
1723
1764
|
itemExp,
|
|
1724
1765
|
indexName,
|
|
@@ -1745,11 +1786,17 @@ class Interpreter {
|
|
|
1745
1786
|
const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
|
|
1746
1787
|
let isFirstRender = true;
|
|
1747
1788
|
forNode.effect = new this.Effect(() => {
|
|
1748
|
-
|
|
1789
|
+
const collection = arrSignal.get();
|
|
1790
|
+
const _this$formatForCollec = this.formatForCollection(collection),
|
|
1791
|
+
formattedArr = _this$formatForCollec.arr,
|
|
1792
|
+
keys = _this$formatForCollec.keys;
|
|
1793
|
+
let arr = formattedArr;
|
|
1749
1794
|
arr[aoye.Keys.Iterator];
|
|
1750
1795
|
const prevCtx = aoye.getPulling();
|
|
1751
1796
|
aoye.setPulling(null);
|
|
1752
|
-
forNode.
|
|
1797
|
+
forNode.reactiveArr = formattedArr;
|
|
1798
|
+
forNode.arr = Array.isArray(collection) ? aoye.toRaw(arr) : arr;
|
|
1799
|
+
forNode.keys = keys;
|
|
1753
1800
|
const children = forNode.children;
|
|
1754
1801
|
if (isFirstRender) {
|
|
1755
1802
|
const len = arr.length;
|
|
@@ -1787,7 +1834,7 @@ class Interpreter {
|
|
|
1787
1834
|
for (let i = minLen; i--;) {
|
|
1788
1835
|
const child = children[i];
|
|
1789
1836
|
newChildren[i] = child;
|
|
1790
|
-
this.reuseForItem(child, arr[i], itemExp, i, indexName);
|
|
1837
|
+
this.reuseForItem(child, arr[i], itemExp, i, indexName, keys?.[i]);
|
|
1791
1838
|
}
|
|
1792
1839
|
} else {
|
|
1793
1840
|
let s = 0,
|
|
@@ -1800,7 +1847,7 @@ class Interpreter {
|
|
|
1800
1847
|
const key = forNode.getKey(itemData);
|
|
1801
1848
|
if (old === key) {
|
|
1802
1849
|
newChildren[s] = child;
|
|
1803
|
-
this.reuseForItem(child, arr[s], itemExp, s, indexName);
|
|
1850
|
+
this.reuseForItem(child, arr[s], itemExp, s, indexName, keys?.[s]);
|
|
1804
1851
|
s++;
|
|
1805
1852
|
} else {
|
|
1806
1853
|
break;
|
|
@@ -1813,7 +1860,7 @@ class Interpreter {
|
|
|
1813
1860
|
const key = forNode.getKey(itemData);
|
|
1814
1861
|
if (old === key) {
|
|
1815
1862
|
newChildren[e2] = child;
|
|
1816
|
-
this.reuseForItem(child, arr[e2], itemExp, e2, indexName);
|
|
1863
|
+
this.reuseForItem(child, arr[e2], itemExp, e2, indexName, keys?.[e2]);
|
|
1817
1864
|
e1--;
|
|
1818
1865
|
e2--;
|
|
1819
1866
|
} else {
|
|
@@ -1855,7 +1902,7 @@ class Interpreter {
|
|
|
1855
1902
|
}
|
|
1856
1903
|
const child = children[i];
|
|
1857
1904
|
newChildren[newI] = child;
|
|
1858
|
-
this.reuseForItem(child, arr[newI], itemExp, newI, indexName);
|
|
1905
|
+
this.reuseForItem(child, arr[newI], itemExp, newI, indexName, keys?.[newI]);
|
|
1859
1906
|
new2oldI[newI - s2] = i;
|
|
1860
1907
|
key2new.delete(key);
|
|
1861
1908
|
if (newI < maxIncNewI) {
|
|
@@ -1941,15 +1988,15 @@ class Interpreter {
|
|
|
1941
1988
|
this.remove(child.realAfter);
|
|
1942
1989
|
child.effect.dispose();
|
|
1943
1990
|
}
|
|
1944
|
-
reuseForItem(child, data, itemExp, i, indexName) {
|
|
1991
|
+
reuseForItem(child, data, itemExp, i, indexName, indexValue) {
|
|
1945
1992
|
if (typeof itemExp === 'string') {
|
|
1946
1993
|
child.data[itemExp] = data;
|
|
1947
1994
|
if (indexName) {
|
|
1948
|
-
child.data[indexName] = i;
|
|
1995
|
+
child.data[indexName] = indexValue ?? i;
|
|
1949
1996
|
}
|
|
1950
1997
|
} else {
|
|
1951
1998
|
indexName = indexName || KEY_INDEX;
|
|
1952
|
-
child.data[indexName] = i;
|
|
1999
|
+
child.data[indexName] = indexValue ?? i;
|
|
1953
2000
|
}
|
|
1954
2001
|
}
|
|
1955
2002
|
forItemId = 0;
|
|
@@ -1983,23 +2030,24 @@ class Interpreter {
|
|
|
1983
2030
|
itemExp = forNode.itemExp,
|
|
1984
2031
|
vars = forNode.vars,
|
|
1985
2032
|
arrSignal = forNode.arrSignal,
|
|
1986
|
-
getKey = forNode.getKey
|
|
2033
|
+
getKey = forNode.getKey,
|
|
2034
|
+
keys = forNode.keys;
|
|
1987
2035
|
let indexName = forNode.indexName;
|
|
1988
2036
|
let data;
|
|
1989
2037
|
if (typeof itemExp === 'string') {
|
|
1990
2038
|
data = aoye.deepSignal(indexName ? {
|
|
1991
2039
|
[itemExp]: arr[i],
|
|
1992
|
-
[indexName]: i
|
|
2040
|
+
[indexName]: keys?.[i] ?? i
|
|
1993
2041
|
} : {
|
|
1994
2042
|
[itemExp]: arr[i]
|
|
1995
2043
|
}, aoye.getPulling());
|
|
1996
2044
|
} else {
|
|
1997
2045
|
indexName = indexName ?? KEY_INDEX;
|
|
1998
2046
|
const rawData = {
|
|
1999
|
-
[indexName]: i
|
|
2047
|
+
[indexName]: keys?.[i] ?? i
|
|
2000
2048
|
};
|
|
2001
2049
|
data = aoye.deepSignal(rawData, aoye.getPulling());
|
|
2002
|
-
const computedData = new aoye.Computed(() => itemExp(arrSignal.get()[getKey ? data[indexName] : i]));
|
|
2050
|
+
const computedData = new aoye.Computed(() => itemExp((arrSignal.get(), forNode.reactiveArr)[getKey ? data[indexName] : keys ? (data[indexName], i) : i]));
|
|
2003
2051
|
const cells = data[aoye.Keys.Meta].cells;
|
|
2004
2052
|
for (let i = 0; i < vars.length; i++) {
|
|
2005
2053
|
const name = vars[i];
|
|
@@ -2404,6 +2452,7 @@ function customRender(option) {
|
|
|
2404
2452
|
tokenizer
|
|
2405
2453
|
};
|
|
2406
2454
|
terp.program(root, componentNode);
|
|
2455
|
+
aoye.flushMicroEffectManual();
|
|
2407
2456
|
return [componentNode, store];
|
|
2408
2457
|
};
|
|
2409
2458
|
}
|
|
@@ -2452,6 +2501,7 @@ Object.defineProperty(exports, "Store", {
|
|
|
2452
2501
|
get: function () { return aoye.Store; }
|
|
2453
2502
|
});
|
|
2454
2503
|
exports.Compiler = Compiler;
|
|
2504
|
+
exports.FakeType = FakeType;
|
|
2455
2505
|
exports.NodeType = NodeType;
|
|
2456
2506
|
exports.ParseSyntaxError = ParseSyntaxError;
|
|
2457
2507
|
exports.Tokenizer = Tokenizer;
|