aoye 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/aoye.cjs.js +26 -12
- package/dist/aoye.cjs.js.map +1 -1
- package/dist/aoye.esm.js +26 -12
- package/dist/aoye.esm.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.umd.js +26 -12
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -206,7 +206,17 @@ declare class Store {
|
|
|
206
206
|
static Current: Store;
|
|
207
207
|
constructor();
|
|
208
208
|
parent: () => Store | null;
|
|
209
|
-
|
|
209
|
+
/**
|
|
210
|
+
* 创建子 Store 实例并传递属性:
|
|
211
|
+
* Store.new({ prop1: `v1+v2`, prop2: (p) => p.v3 * p.v4 }, { prop3: 123 })
|
|
212
|
+
*
|
|
213
|
+
* keyMap:childKey → 表达式
|
|
214
|
+
* - string:解析为 with(parentStore) { ... } 表达式,结果包装为 Computed
|
|
215
|
+
* - Function:直接包装为 Computed(() => fn(parentStore))
|
|
216
|
+
*
|
|
217
|
+
* staticMap:childKey → 静态值,直接赋值
|
|
218
|
+
*/
|
|
219
|
+
static new<T extends Store = any, P extends Store = any, O extends string = ''>(this: new (...args: any[]) => T, keyMap?: PRecord<keyof T, keyof Omit<P, O> | DeepOmitPath<P, O>> | Record<string, string | Function>, staticMap?: PRecord<keyof T, any>): T;
|
|
210
220
|
map<P extends Store = any, O extends string = ''>(keyMap?: PRecord<keyof this, keyof Omit<P, O> | DeepOmitPath<P, O>>): void;
|
|
211
221
|
}
|
|
212
222
|
|
package/dist/index.umd.js
CHANGED
|
@@ -769,10 +769,10 @@
|
|
|
769
769
|
}
|
|
770
770
|
iter.get();
|
|
771
771
|
};
|
|
772
|
-
const triggerIterator =
|
|
772
|
+
const triggerIterator = cells => {
|
|
773
773
|
const iter = cells.get(Keys.Iterator);
|
|
774
774
|
if (iter) {
|
|
775
|
-
iter.set((
|
|
775
|
+
iter.set((iter.value || 0) + 1);
|
|
776
776
|
}
|
|
777
777
|
};
|
|
778
778
|
const trackKey = (cells, scope, key) => {
|
|
@@ -824,7 +824,7 @@
|
|
|
824
824
|
if (had) {
|
|
825
825
|
triggerKey(cells, key);
|
|
826
826
|
cells.delete(key);
|
|
827
|
-
triggerIterator(cells
|
|
827
|
+
triggerIterator(cells);
|
|
828
828
|
}
|
|
829
829
|
batchEnd();
|
|
830
830
|
return result;
|
|
@@ -838,7 +838,7 @@
|
|
|
838
838
|
cells.clear();
|
|
839
839
|
if (iterCell) cells.set(Keys.Iterator, iterCell);
|
|
840
840
|
if (hadItems) {
|
|
841
|
-
triggerIterator(cells
|
|
841
|
+
triggerIterator(cells);
|
|
842
842
|
}
|
|
843
843
|
batchEnd();
|
|
844
844
|
},
|
|
@@ -883,7 +883,7 @@
|
|
|
883
883
|
} else {
|
|
884
884
|
cell.set(value);
|
|
885
885
|
}
|
|
886
|
-
triggerIterator(cells
|
|
886
|
+
triggerIterator(cells);
|
|
887
887
|
batchEnd();
|
|
888
888
|
return this;
|
|
889
889
|
}
|
|
@@ -903,7 +903,7 @@
|
|
|
903
903
|
cell.set(value);
|
|
904
904
|
}
|
|
905
905
|
if (!had) {
|
|
906
|
-
triggerIterator(cells
|
|
906
|
+
triggerIterator(cells);
|
|
907
907
|
}
|
|
908
908
|
batchEnd();
|
|
909
909
|
return this;
|
|
@@ -1406,6 +1406,7 @@
|
|
|
1406
1406
|
args[0] = wrapCb;
|
|
1407
1407
|
}
|
|
1408
1408
|
|
|
1409
|
+
const isParentKey = (parentStore, expr) => expr in parentStore[Keys.Raw];
|
|
1409
1410
|
class Store {
|
|
1410
1411
|
static [IsStore] = true;
|
|
1411
1412
|
static [StoreIgnoreKeys] = ['ui', 'raw'];
|
|
@@ -1416,18 +1417,31 @@
|
|
|
1416
1417
|
return proxy;
|
|
1417
1418
|
}
|
|
1418
1419
|
parent = () => null;
|
|
1419
|
-
static new(keyMap
|
|
1420
|
+
static new(keyMap, staticMap) {
|
|
1420
1421
|
const parentStore = Store.Current;
|
|
1421
1422
|
const child = new this();
|
|
1422
|
-
if (parentStore) {
|
|
1423
|
+
if (parentStore && keyMap) {
|
|
1424
|
+
const cells = child[Keys.Meta].cells;
|
|
1423
1425
|
for (const childKey in keyMap) {
|
|
1424
|
-
const
|
|
1425
|
-
|
|
1426
|
+
const expr = keyMap[childKey];
|
|
1427
|
+
if (typeof expr === 'function') {
|
|
1428
|
+
cells.set(childKey, new Computed(() => expr(parentStore)));
|
|
1429
|
+
child[Keys.Raw][childKey] = undefined;
|
|
1430
|
+
} else if (typeof expr === 'string') {
|
|
1431
|
+
if (isParentKey(parentStore, expr)) {
|
|
1432
|
+
shareSignal(parentStore, expr, child, childKey);
|
|
1433
|
+
} else {
|
|
1434
|
+
const fn = new Function('data', `let v;with(data){v=${expr};}return v;`);
|
|
1435
|
+
cells.set(childKey, new Computed(() => fn(parentStore)));
|
|
1436
|
+
child[Keys.Raw][childKey] = undefined;
|
|
1437
|
+
}
|
|
1438
|
+
} else {
|
|
1439
|
+
shareSignal(parentStore, expr, child, childKey);
|
|
1440
|
+
}
|
|
1426
1441
|
}
|
|
1427
1442
|
}
|
|
1428
1443
|
for (const key in staticMap) {
|
|
1429
|
-
|
|
1430
|
-
child[key] = value;
|
|
1444
|
+
child[key] = staticMap[key];
|
|
1431
1445
|
}
|
|
1432
1446
|
child.parent = () => parentStore;
|
|
1433
1447
|
Store.Current = parentStore;
|