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
package/dist/bobe.cjs.js
CHANGED
|
@@ -243,6 +243,7 @@ class Tokenizer {
|
|
|
243
243
|
}
|
|
244
244
|
isEof() {
|
|
245
245
|
if (!this.token) return false;
|
|
246
|
+
if (this.i >= this.code.length && !this.waitingTokens.len) return true;
|
|
246
247
|
return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
|
|
247
248
|
}
|
|
248
249
|
setToken(type, value, dt = 1) {
|
|
@@ -1656,6 +1657,44 @@ class Interpreter {
|
|
|
1656
1657
|
node.realAfter = this.insertAfterAnchor('context-after');
|
|
1657
1658
|
return node;
|
|
1658
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
|
+
}
|
|
1659
1698
|
forDeclaration() {
|
|
1660
1699
|
const arrExp = this.tokenizer.jsExp().value;
|
|
1661
1700
|
this.tokenizer.nextToken();
|
|
@@ -1692,6 +1731,8 @@ class Interpreter {
|
|
|
1692
1731
|
realBefore: prevSibling?.realAfter || prevSibling,
|
|
1693
1732
|
realAfter: null,
|
|
1694
1733
|
arr: null,
|
|
1734
|
+
reactiveArr: null,
|
|
1735
|
+
keys: null,
|
|
1695
1736
|
arrSignal: null,
|
|
1696
1737
|
itemExp,
|
|
1697
1738
|
indexName,
|
|
@@ -1718,11 +1759,17 @@ class Interpreter {
|
|
|
1718
1759
|
const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
|
|
1719
1760
|
let isFirstRender = true;
|
|
1720
1761
|
forNode.effect = new this.Effect(() => {
|
|
1721
|
-
|
|
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;
|
|
1722
1767
|
arr[aoye.Keys.Iterator];
|
|
1723
1768
|
const prevCtx = aoye.getPulling();
|
|
1724
1769
|
aoye.setPulling(null);
|
|
1725
|
-
forNode.
|
|
1770
|
+
forNode.reactiveArr = formattedArr;
|
|
1771
|
+
forNode.arr = Array.isArray(collection) ? aoye.toRaw(arr) : arr;
|
|
1772
|
+
forNode.keys = keys;
|
|
1726
1773
|
const children = forNode.children;
|
|
1727
1774
|
if (isFirstRender) {
|
|
1728
1775
|
const len = arr.length;
|
|
@@ -1760,7 +1807,7 @@ class Interpreter {
|
|
|
1760
1807
|
for (let i = minLen; i--;) {
|
|
1761
1808
|
const child = children[i];
|
|
1762
1809
|
newChildren[i] = child;
|
|
1763
|
-
this.reuseForItem(child, arr[i], itemExp, i, indexName);
|
|
1810
|
+
this.reuseForItem(child, arr[i], itemExp, i, indexName, keys?.[i]);
|
|
1764
1811
|
}
|
|
1765
1812
|
} else {
|
|
1766
1813
|
let s = 0,
|
|
@@ -1773,7 +1820,7 @@ class Interpreter {
|
|
|
1773
1820
|
const key = forNode.getKey(itemData);
|
|
1774
1821
|
if (old === key) {
|
|
1775
1822
|
newChildren[s] = child;
|
|
1776
|
-
this.reuseForItem(child, arr[s], itemExp, s, indexName);
|
|
1823
|
+
this.reuseForItem(child, arr[s], itemExp, s, indexName, keys?.[s]);
|
|
1777
1824
|
s++;
|
|
1778
1825
|
} else {
|
|
1779
1826
|
break;
|
|
@@ -1786,7 +1833,7 @@ class Interpreter {
|
|
|
1786
1833
|
const key = forNode.getKey(itemData);
|
|
1787
1834
|
if (old === key) {
|
|
1788
1835
|
newChildren[e2] = child;
|
|
1789
|
-
this.reuseForItem(child, arr[e2], itemExp, e2, indexName);
|
|
1836
|
+
this.reuseForItem(child, arr[e2], itemExp, e2, indexName, keys?.[e2]);
|
|
1790
1837
|
e1--;
|
|
1791
1838
|
e2--;
|
|
1792
1839
|
} else {
|
|
@@ -1828,7 +1875,7 @@ class Interpreter {
|
|
|
1828
1875
|
}
|
|
1829
1876
|
const child = children[i];
|
|
1830
1877
|
newChildren[newI] = child;
|
|
1831
|
-
this.reuseForItem(child, arr[newI], itemExp, newI, indexName);
|
|
1878
|
+
this.reuseForItem(child, arr[newI], itemExp, newI, indexName, keys?.[newI]);
|
|
1832
1879
|
new2oldI[newI - s2] = i;
|
|
1833
1880
|
key2new.delete(key);
|
|
1834
1881
|
if (newI < maxIncNewI) {
|
|
@@ -1914,15 +1961,15 @@ class Interpreter {
|
|
|
1914
1961
|
this.remove(child.realAfter);
|
|
1915
1962
|
child.effect.dispose();
|
|
1916
1963
|
}
|
|
1917
|
-
reuseForItem(child, data, itemExp, i, indexName) {
|
|
1964
|
+
reuseForItem(child, data, itemExp, i, indexName, indexValue) {
|
|
1918
1965
|
if (typeof itemExp === 'string') {
|
|
1919
1966
|
child.data[itemExp] = data;
|
|
1920
1967
|
if (indexName) {
|
|
1921
|
-
child.data[indexName] = i;
|
|
1968
|
+
child.data[indexName] = indexValue ?? i;
|
|
1922
1969
|
}
|
|
1923
1970
|
} else {
|
|
1924
1971
|
indexName = indexName || KEY_INDEX;
|
|
1925
|
-
child.data[indexName] = i;
|
|
1972
|
+
child.data[indexName] = indexValue ?? i;
|
|
1926
1973
|
}
|
|
1927
1974
|
}
|
|
1928
1975
|
forItemId = 0;
|
|
@@ -1956,23 +2003,24 @@ class Interpreter {
|
|
|
1956
2003
|
itemExp = forNode.itemExp,
|
|
1957
2004
|
vars = forNode.vars,
|
|
1958
2005
|
arrSignal = forNode.arrSignal,
|
|
1959
|
-
getKey = forNode.getKey
|
|
2006
|
+
getKey = forNode.getKey,
|
|
2007
|
+
keys = forNode.keys;
|
|
1960
2008
|
let indexName = forNode.indexName;
|
|
1961
2009
|
let data;
|
|
1962
2010
|
if (typeof itemExp === 'string') {
|
|
1963
2011
|
data = aoye.deepSignal(indexName ? {
|
|
1964
2012
|
[itemExp]: arr[i],
|
|
1965
|
-
[indexName]: i
|
|
2013
|
+
[indexName]: keys?.[i] ?? i
|
|
1966
2014
|
} : {
|
|
1967
2015
|
[itemExp]: arr[i]
|
|
1968
2016
|
}, aoye.getPulling());
|
|
1969
2017
|
} else {
|
|
1970
2018
|
indexName = indexName ?? KEY_INDEX;
|
|
1971
2019
|
const rawData = {
|
|
1972
|
-
[indexName]: i
|
|
2020
|
+
[indexName]: keys?.[i] ?? i
|
|
1973
2021
|
};
|
|
1974
2022
|
data = aoye.deepSignal(rawData, aoye.getPulling());
|
|
1975
|
-
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]));
|
|
1976
2024
|
const cells = data[aoye.Keys.Meta].cells;
|
|
1977
2025
|
for (let i = 0; i < vars.length; i++) {
|
|
1978
2026
|
const name = vars[i];
|
|
@@ -2377,6 +2425,7 @@ function customRender(option) {
|
|
|
2377
2425
|
tokenizer
|
|
2378
2426
|
};
|
|
2379
2427
|
terp.program(root, componentNode);
|
|
2428
|
+
aoye.flushMicroEffectManual();
|
|
2380
2429
|
return [componentNode, store];
|
|
2381
2430
|
};
|
|
2382
2431
|
}
|
|
@@ -2425,6 +2474,7 @@ Object.defineProperty(exports, "Store", {
|
|
|
2425
2474
|
get: function () { return aoye.Store; }
|
|
2426
2475
|
});
|
|
2427
2476
|
exports.Compiler = Compiler;
|
|
2477
|
+
exports.FakeType = FakeType;
|
|
2428
2478
|
exports.NodeType = NodeType;
|
|
2429
2479
|
exports.ParseSyntaxError = ParseSyntaxError;
|
|
2430
2480
|
exports.Tokenizer = Tokenizer;
|