aoye 0.0.19 → 0.0.21

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.esm.js CHANGED
@@ -241,9 +241,9 @@ class Scheduler {
241
241
  var _a;
242
242
  if (!this.firstEffectItem) return;
243
243
  const subQueue = this.effectQueue.subRef(this.firstEffectItem, this.lastEffectItem);
244
- (_a = this.onOneSetEffectsAdded) == null ? void 0 : _a.call(this, subQueue, this.effectQueue);
245
244
  this.firstEffectItem = null;
246
245
  this.lastEffectItem = null;
246
+ (_a = this.onOneSetEffectsAdded) == null ? void 0 : _a.call(this, subQueue, this.effectQueue);
247
247
  }
248
248
  addEffect(effect) {
249
249
  var _a;
@@ -259,8 +259,8 @@ Scheduler.Macro = "__Macro_";
259
259
  class SyncScheduler extends Scheduler {
260
260
  onOneSetEffectsAdded(subQueue, queue) {
261
261
  subQueue.forEach((effect, item) => {
262
- effect.runIfDirty();
263
262
  queue.delete(item);
263
+ effect.runIfDirty();
264
264
  });
265
265
  }
266
266
  }
@@ -272,8 +272,8 @@ class MicroScheduler extends Scheduler {
272
272
  onOneSetEffectsAdded(subQueue, queue) {
273
273
  const task = () => {
274
274
  subQueue.forEach((effect, item) => {
275
- effect.runIfDirty();
276
275
  queue.delete(item);
276
+ effect.runIfDirty();
277
277
  });
278
278
  return {
279
279
  finished: true,
@@ -292,8 +292,8 @@ class MacroScheduler extends Scheduler {
292
292
  onOneSetEffectsAdded(subQueue, queue) {
293
293
  const task = () => {
294
294
  subQueue.forEach((effect, item) => {
295
- effect.runIfDirty();
296
295
  queue.delete(item);
296
+ effect.runIfDirty();
297
297
  });
298
298
  };
299
299
  task.time = Date.now();
@@ -308,8 +308,8 @@ class LayoutScheduler extends Scheduler {
308
308
  onOneSetEffectsAdded(subQueue, queue) {
309
309
  const task = () => {
310
310
  subQueue.forEach((effect, item) => {
311
- effect.runIfDirty();
312
311
  queue.delete(item);
312
+ effect.runIfDirty();
313
313
  });
314
314
  };
315
315
  task.time = Date.now();
@@ -322,6 +322,7 @@ const _scheduler = {
322
322
  [Scheduler.Macro]: new MacroScheduler(),
323
323
  [Scheduler.Layout]: new LayoutScheduler()
324
324
  };
325
+ globalThis["sche"] = _scheduler[Scheduler.Sync];
325
326
  const registerScheduler = (key, Ctor) => _scheduler[key] = new Ctor();
326
327
 
327
328
  var __defProp$2 = Object.defineProperty;
@@ -710,6 +711,9 @@ const markDeep = (signal) => {
710
711
  updatedSchedulers.add(key);
711
712
  }
712
713
  level++;
714
+ if (isLeaf) {
715
+ return true;
716
+ }
713
717
  }
714
718
  });
715
719
  if (batch.inBatch()) return;
@@ -769,13 +773,7 @@ const _Signal = class _Signal {
769
773
  var _a, _b;
770
774
  G.PullingRecurseDeep++;
771
775
  const downstream = G.PullingSignal;
772
- const isScope = this.state & State.IsScope;
773
- if (this !== downstream && // 1. 外部支持 link
774
- shouldLink && // 2. 有下游
775
- downstream && // 3. 下游是 watcher,不链接非 scope
776
- ((downstream.state & State.LinkScopeOnly) === 0 || isScope)) {
777
- Line.link(this, downstream);
778
- }
776
+ this.linkWhenPull(downstream);
779
777
  try {
780
778
  if (this.version === G.version) {
781
779
  return this.value;
@@ -786,7 +784,7 @@ const _Signal = class _Signal {
786
784
  (_a = this.clean) == null ? void 0 : _a.call(this);
787
785
  this.clean = null;
788
786
  let v = this.pull();
789
- if (isScope && typeof v === "function") {
787
+ if (this.state & State.IsScope && typeof v === "function") {
790
788
  const fn = v;
791
789
  this.clean = () => runWithPulling(fn, null);
792
790
  v = this.value;
@@ -806,6 +804,20 @@ const _Signal = class _Signal {
806
804
  G.PullingRecurseDeep--;
807
805
  }
808
806
  }
807
+ linkWhenPull(downstream) {
808
+ const isScope = this.state & State.IsScope;
809
+ if (this !== downstream && // 2. 有下游
810
+ downstream && // 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
811
+ ((downstream.state & State.LinkScopeOnly) === 0 || isScope) && /**4. scope 只能被一个下游节点管理,就是初始化它的那个下游节点
812
+ * 发生在 outEffect(() => scope(() => innerEffect(), null))
813
+ * 虽然通过 scope 让 innerEffect 被管理,
814
+ * 如果 innerEffect 在 outEffect 中被再次触发,就导致其被 outEffect 管理,
815
+ * 若 outEffect 后续重新触发, 则导致 innerEffect 被销毁
816
+ */
817
+ (!isScope || !this.emitStart)) {
818
+ Line.link(this, downstream);
819
+ }
820
+ }
809
821
  pullDeep() {
810
822
  const signal = this;
811
823
  if (signal.state & DirtyState) {
@@ -854,11 +866,7 @@ const _Signal = class _Signal {
854
866
  });
855
867
  }
856
868
  const downstream = G.PullingSignal;
857
- if (this !== downstream && // 2. 有下游
858
- downstream && // 3. 下游是 watcher 不是 watch,或 是watcher 但 当前是 scope
859
- ((downstream.state & State.LinkScopeOnly) === 0 || this.state & State.IsScope)) {
860
- Line.link(this, downstream);
861
- }
869
+ this.linkWhenPull(downstream);
862
870
  return this.value;
863
871
  }
864
872
  get v() {
@@ -1026,10 +1034,11 @@ const shareSignal = (from, fromPath, to, toPath) => {
1026
1034
  const formPaths = Array.isArray(fromPath) ? fromPath : fromPath.split(".");
1027
1035
  runWithPulling(() => {
1028
1036
  const { target: fromTarget, key: fromKey } = getTargetAndKey(from, formPaths);
1029
- fromTarget[fromKey];
1037
+ const val = fromTarget[fromKey];
1030
1038
  const fromSignal = fromTarget[Keys.Meta].cells.get(fromKey);
1031
1039
  const { target: toTarget, key: toKey } = getTargetAndKey(to, toPaths);
1032
1040
  toTarget[Keys.Meta].cells.set(toKey, fromSignal);
1041
+ toTarget[Keys.Raw][toKey] = val;
1033
1042
  }, null);
1034
1043
  } catch (error) {
1035
1044
  console.error("\u6620\u5C04\u4E86\u4E0D\u5B58\u5728\u7684Key\uFF01");
@@ -1507,13 +1516,21 @@ const effect = (customPull, depOrOpt, opt) => {
1507
1516
  bound.ins = s;
1508
1517
  return bound;
1509
1518
  };
1510
- const scope = (customPull) => {
1519
+ const scope = (...args) => {
1520
+ const hasScope = args.length > 1;
1511
1521
  const s = Signal.create(null, {
1512
- customPull,
1522
+ customPull: args[0],
1513
1523
  scheduler: Scheduler.Sync,
1514
- isScope: true
1524
+ isScope: true,
1525
+ scope: hasScope ? args[1] : G.PullingSignal
1515
1526
  });
1516
- s.v;
1527
+ if (hasScope) {
1528
+ runWithPulling(() => {
1529
+ s.v;
1530
+ }, args[1]);
1531
+ } else {
1532
+ s.v;
1533
+ }
1517
1534
  s.state |= State.ScopeReady;
1518
1535
  const bound = dispose.bind(s);
1519
1536
  bound.ins = s;
@@ -1531,5 +1548,5 @@ const isScope = (value) => {
1531
1548
  return value instanceof Signal;
1532
1549
  };
1533
1550
 
1534
- export { $, IsStore, Keys, Scheduler, Store, StoreIgnoreKeys, TaskQueue, batch, clean, customEffect, deepSignal, effect, getPulling, isScope, isSignal, registerScheduler, runWithPulling, scope, setPulling, shareSignal };
1551
+ export { $, IsStore, Keys, Scheduler, Signal, Store, StoreIgnoreKeys, TaskQueue, batch, clean, customEffect, deepSignal, effect, getPulling, isScope, isSignal, registerScheduler, runWithPulling, scope, setPulling, shareSignal, toRaw };
1535
1552
  //# sourceMappingURL=aoye.esm.js.map