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