aoye 0.0.53 → 0.0.55

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/index.d.ts CHANGED
@@ -130,6 +130,7 @@ declare class Signal<T = any> {
130
130
  set(v: T): void;
131
131
  }
132
132
 
133
+ declare function flushMicroEffectManual(): void;
133
134
  declare const batchStart: () => number;
134
135
  declare const batchEnd: () => void;
135
136
  /** effect、computed 回调执行的唯一 id
@@ -206,7 +207,17 @@ declare class Store {
206
207
  static Current: Store;
207
208
  constructor();
208
209
  parent: () => Store | null;
209
- 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>>, staticMap?: PRecord<keyof T, any>): T;
210
+ /**
211
+ * 创建子 Store 实例并传递属性:
212
+ * Store.new({ prop1: `v1+v2`, prop2: (p) => p.v3 * p.v4 }, { prop3: 123 })
213
+ *
214
+ * keyMap:childKey → 表达式
215
+ * - string:解析为 with(parentStore) { ... } 表达式,结果包装为 Computed
216
+ * - Function:直接包装为 Computed(() => fn(parentStore))
217
+ *
218
+ * staticMap:childKey → 静态值,直接赋值
219
+ */
220
+ 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
221
  map<P extends Store = any, O extends string = ''>(keyMap?: PRecord<keyof this, keyof Omit<P, O> | DeepOmitPath<P, O>>): void;
211
222
  }
212
223
 
@@ -233,5 +244,5 @@ declare function effectUt(callback: (...args: ValueDiff[]) => void, depOrOpt?: a
233
244
  declare function effect(callback: (...args: ValueDiff[]) => void, depOrOpt?: any[] | CustomEffectOpt, opt?: CustomEffectOpt): Effect;
234
245
  declare function scope(...args: any[]): any;
235
246
 
236
- export { $, Computed, Effect, EffectStrType2Enum, IsStore, Keys, NoopEffect, ScheduleStatus, ScheduleType, Scope, Signal, Store, StoreIgnoreKeys, batchDeep, batchEnd, batchStart, clean, deepSignal, effect, effectUt, execId, execIdInc, getPulling, ide, macro, micro, noopEffect, now, runWithPulling, scope, setExecId, setPulling, shareSignal, toRaw };
247
+ export { $, Computed, Effect, EffectStrType2Enum, IsStore, Keys, NoopEffect, ScheduleStatus, ScheduleType, Scope, Signal, Store, StoreIgnoreKeys, batchDeep, batchEnd, batchStart, clean, deepSignal, effect, effectUt, execId, execIdInc, flushMicroEffectManual, getPulling, ide, macro, micro, noopEffect, now, runWithPulling, scope, setExecId, setPulling, shareSignal, toRaw };
237
248
  export type { CreateScope, CreateTaskProps, CustomEffectOpt, DeepOmitPath, DeepPath, DeepValue, Dispose, Key, Link, MatchValue, Mix, OnClean, OutLink, PRecord, ScheduleTypeStr, SideEffect, SignalNode, SignalType, Task, TaskControlReturn, ValueDiff };
package/dist/index.umd.js CHANGED
@@ -301,6 +301,13 @@
301
301
  });
302
302
  }
303
303
  }
304
+ function flushMicroEffectManual() {
305
+ if (schedulerStatus !== ScheduleStatus.Running && multiScheduler.hasTask) {
306
+ schedulerStatus = ScheduleStatus.Running;
307
+ multiScheduler.flushAllTask();
308
+ schedulerStatus = ScheduleStatus.Idle;
309
+ }
310
+ }
304
311
  let _batchDeep = 0;
305
312
  const batchStart = () => _batchDeep++;
306
313
  const batchEnd = () => {
@@ -769,10 +776,10 @@
769
776
  }
770
777
  iter.get();
771
778
  };
772
- const triggerIterator = (cells, raw) => {
779
+ const triggerIterator = cells => {
773
780
  const iter = cells.get(Keys.Iterator);
774
781
  if (iter) {
775
- iter.set((raw[Keys.Iterator] || 0) + 1);
782
+ iter.set((iter.value || 0) + 1);
776
783
  }
777
784
  };
778
785
  const trackKey = (cells, scope, key) => {
@@ -824,7 +831,7 @@
824
831
  if (had) {
825
832
  triggerKey(cells, key);
826
833
  cells.delete(key);
827
- triggerIterator(cells, target);
834
+ triggerIterator(cells);
828
835
  }
829
836
  batchEnd();
830
837
  return result;
@@ -838,7 +845,7 @@
838
845
  cells.clear();
839
846
  if (iterCell) cells.set(Keys.Iterator, iterCell);
840
847
  if (hadItems) {
841
- triggerIterator(cells, target);
848
+ triggerIterator(cells);
842
849
  }
843
850
  batchEnd();
844
851
  },
@@ -883,7 +890,7 @@
883
890
  } else {
884
891
  cell.set(value);
885
892
  }
886
- triggerIterator(cells, target);
893
+ triggerIterator(cells);
887
894
  batchEnd();
888
895
  return this;
889
896
  }
@@ -903,7 +910,7 @@
903
910
  cell.set(value);
904
911
  }
905
912
  if (!had) {
906
- triggerIterator(cells, target);
913
+ triggerIterator(cells);
907
914
  }
908
915
  batchEnd();
909
916
  return this;
@@ -1406,6 +1413,7 @@
1406
1413
  args[0] = wrapCb;
1407
1414
  }
1408
1415
 
1416
+ const isParentKey = (parentStore, expr) => expr in parentStore[Keys.Raw];
1409
1417
  class Store {
1410
1418
  static [IsStore] = true;
1411
1419
  static [StoreIgnoreKeys] = ['ui', 'raw'];
@@ -1416,18 +1424,31 @@
1416
1424
  return proxy;
1417
1425
  }
1418
1426
  parent = () => null;
1419
- static new(keyMap = {}, staticMap = {}) {
1427
+ static new(keyMap, staticMap) {
1420
1428
  const parentStore = Store.Current;
1421
1429
  const child = new this();
1422
- if (parentStore) {
1430
+ if (parentStore && keyMap) {
1431
+ const cells = child[Keys.Meta].cells;
1423
1432
  for (const childKey in keyMap) {
1424
- const parentKey = keyMap[childKey];
1425
- shareSignal(parentStore, parentKey, child, childKey);
1433
+ const expr = keyMap[childKey];
1434
+ if (typeof expr === 'function') {
1435
+ cells.set(childKey, new Computed(() => expr(parentStore)));
1436
+ child[Keys.Raw][childKey] = undefined;
1437
+ } else if (typeof expr === 'string') {
1438
+ if (isParentKey(parentStore, expr)) {
1439
+ shareSignal(parentStore, expr, child, childKey);
1440
+ } else {
1441
+ const fn = new Function('data', `let v;with(data){v=${expr};}return v;`);
1442
+ cells.set(childKey, new Computed(() => fn(parentStore)));
1443
+ child[Keys.Raw][childKey] = undefined;
1444
+ }
1445
+ } else {
1446
+ shareSignal(parentStore, expr, child, childKey);
1447
+ }
1426
1448
  }
1427
1449
  }
1428
1450
  for (const key in staticMap) {
1429
- const value = staticMap[key];
1430
- child[key] = value;
1451
+ child[key] = staticMap[key];
1431
1452
  }
1432
1453
  child.parent = () => parentStore;
1433
1454
  Store.Current = parentStore;
@@ -1583,6 +1604,7 @@
1583
1604
  exports.effectUt = effectUt;
1584
1605
  exports.execId = execId;
1585
1606
  exports.execIdInc = execIdInc;
1607
+ exports.flushMicroEffectManual = flushMicroEffectManual;
1586
1608
  exports.getPulling = getPulling;
1587
1609
  exports.ide = ide;
1588
1610
  exports.macro = macro;