@lytjs/reactivity 6.0.0 → 6.4.0

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.cts CHANGED
@@ -1,8 +1,8 @@
1
- import { U as UnwrapNestedRefs, D as DeepReadonly, C as ComputedGetter, W as WritableComputedOptions, a as WritableComputedRef, b as WatchSource, c as WatchCallbackWithImmediate, d as WatchOptions, e as WatchHandle, O as OnCleanup, f as WatchEffectOptions } from './types-CMYee6LB.cjs';
2
- export { g as ComputedSetter, h as DebuggerEvent, R as ReactiveEffectOptions, i as ReactiveEffectRunner, j as ReactiveObject, T as ToRefs, k as UnwrapRef, l as WatchCallback, m as batch, n as batchAsync, o as effect, p as enableTracking, q as getSkippedTrackingCount, r as onEffectCleanup, s as pauseTracking, t as resetSkippedTrackingCount, u as resetTracking, v as shouldSkipTracking, w as stop, x as untrack, y as withFirstRenderOptimization } from './types-CMYee6LB.cjs';
1
+ import { U as UnwrapNestedRefs, b as DeepReadonly, C as ComputedGetter, l as WritableComputedOptions, m as WritableComputedRef, k as WatchSource, g as WatchCallbackWithImmediate, j as WatchOptions, i as WatchHandle, O as OnCleanup, h as WatchEffectOptions } from './scope-BC3djHz7.cjs';
2
+ export { a as ComputedSetter, D as DebuggerEvent, E as EffectScope, c as EffectScopeOptions, R as ReactiveEffectOptions, d as ReactiveEffectRunner, e as ReactiveObject, T as ToRefs, f as UnwrapRef, W as WatchCallback, n as batch, o as batchAsync, p as effect, q as effectScope, r as enableTracking, s as getCurrentScope, t as getSkippedTrackingCount, u as onEffectCleanup, v as onScopeDispose, w as pauseTracking, x as resetSkippedTrackingCount, y as resetTracking, z as shouldSkipTracking, A as stop, B as untrack, F as withFirstRenderOptimization } from './scope-BC3djHz7.cjs';
3
3
  import { C as ComputedRef } from './ref-CwOCKoy2.cjs';
4
4
  export { R as Ref, S as ShallowRef, c as customRef, i as isComputedRef, a as isShallowRef, r as ref, s as shallowRef, t as toRef, b as toRefs, d as toValue, e as triggerRef, u as unref } from './ref-CwOCKoy2.cjs';
5
- export { C as ComputedRefSymbol, a as ComputedSignal, R as ReactiveSymbol, b as ReadonlySignal, c as ReadonlySymbol, d as RefSymbol, S as ShallowRefSymbol, e as Signal, f as Subscriber, W as WritableComputedSignal, g as WritableSignal, h as computedSignal, r as readonlySignal, s as set, i as signal, j as signalBatch, k as signalComputed, l as signalUntrack, u as update, v as valueOf, w as writableComputedSignal } from './signal-BOAyevht.cjs';
5
+ export { C as ComputedRefSymbol, a as ComputedSignal, R as ReactiveSymbol, b as ReadonlySignal, c as ReadonlySymbol, d as RefSymbol, S as ShallowRefSymbol, e as Signal, f as Subscriber, W as WritableComputedSignal, g as WritableSignal, m as computedSignal, r as readonlySignal, s as set, n as signal, o as signalBatch, l as signalComputed, p as signalUntrack, u as update, v as valueOf, w as writableComputedSignal } from './signal-DWrUYmvd.cjs';
6
6
  import { RefLike } from '@lytjs/shared-types';
7
7
 
8
8
  /**
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { U as UnwrapNestedRefs, D as DeepReadonly, C as ComputedGetter, W as WritableComputedOptions, a as WritableComputedRef, b as WatchSource, c as WatchCallbackWithImmediate, d as WatchOptions, e as WatchHandle, O as OnCleanup, f as WatchEffectOptions } from './types-CXeWWYm6.js';
2
- export { g as ComputedSetter, h as DebuggerEvent, R as ReactiveEffectOptions, i as ReactiveEffectRunner, j as ReactiveObject, T as ToRefs, k as UnwrapRef, l as WatchCallback, m as batch, n as batchAsync, o as effect, p as enableTracking, q as getSkippedTrackingCount, r as onEffectCleanup, s as pauseTracking, t as resetSkippedTrackingCount, u as resetTracking, v as shouldSkipTracking, w as stop, x as untrack, y as withFirstRenderOptimization } from './types-CXeWWYm6.js';
1
+ import { U as UnwrapNestedRefs, b as DeepReadonly, C as ComputedGetter, l as WritableComputedOptions, m as WritableComputedRef, k as WatchSource, g as WatchCallbackWithImmediate, j as WatchOptions, i as WatchHandle, O as OnCleanup, h as WatchEffectOptions } from './scope-CTxSo201.js';
2
+ export { a as ComputedSetter, D as DebuggerEvent, E as EffectScope, c as EffectScopeOptions, R as ReactiveEffectOptions, d as ReactiveEffectRunner, e as ReactiveObject, T as ToRefs, f as UnwrapRef, W as WatchCallback, n as batch, o as batchAsync, p as effect, q as effectScope, r as enableTracking, s as getCurrentScope, t as getSkippedTrackingCount, u as onEffectCleanup, v as onScopeDispose, w as pauseTracking, x as resetSkippedTrackingCount, y as resetTracking, z as shouldSkipTracking, A as stop, B as untrack, F as withFirstRenderOptimization } from './scope-CTxSo201.js';
3
3
  import { C as ComputedRef } from './ref-CwOCKoy2.js';
4
4
  export { R as Ref, S as ShallowRef, c as customRef, i as isComputedRef, a as isShallowRef, r as ref, s as shallowRef, t as toRef, b as toRefs, d as toValue, e as triggerRef, u as unref } from './ref-CwOCKoy2.js';
5
- export { C as ComputedRefSymbol, a as ComputedSignal, R as ReactiveSymbol, b as ReadonlySignal, c as ReadonlySymbol, d as RefSymbol, S as ShallowRefSymbol, e as Signal, f as Subscriber, W as WritableComputedSignal, g as WritableSignal, h as computedSignal, r as readonlySignal, s as set, i as signal, j as signalBatch, k as signalComputed, l as signalUntrack, u as update, v as valueOf, w as writableComputedSignal } from './signal-BOAyevht.js';
5
+ export { C as ComputedRefSymbol, a as ComputedSignal, R as ReactiveSymbol, b as ReadonlySignal, c as ReadonlySymbol, d as RefSymbol, S as ShallowRefSymbol, e as Signal, f as Subscriber, W as WritableComputedSignal, g as WritableSignal, m as computedSignal, r as readonlySignal, s as set, n as signal, o as signalBatch, l as signalComputed, p as signalUntrack, u as update, v as valueOf, w as writableComputedSignal } from './signal-DWrUYmvd.js';
6
6
  import { RefLike } from '@lytjs/shared-types';
7
7
 
8
8
  /**
package/dist/index.mjs CHANGED
@@ -222,7 +222,7 @@ function notifySubscribers(subscribers, store, signalKey, newValue) {
222
222
  next = it.next();
223
223
  }
224
224
  if (store && signalKey !== void 0) {
225
- trigger(store, TriggerOpTypes.SET, signalKey);
225
+ trigger(store, TriggerOpTypes.SET, signalKey, newValue);
226
226
  }
227
227
  }
228
228
  function flushPendingNotifications() {
@@ -278,6 +278,71 @@ function readonlySignal(sig) {
278
278
  Object.defineProperty(readonlyFn, SignalSymbol, { value: true });
279
279
  return readonlyFn;
280
280
  }
281
+ var activeEffectScope;
282
+ function getActiveEffectScope() {
283
+ return activeEffectScope;
284
+ }
285
+ function effectScope(options) {
286
+ const detached = typeof options === "boolean" ? options : options?.detached;
287
+ const scope = {
288
+ active: true,
289
+ effects: [],
290
+ cleanups: [],
291
+ parent: activeEffectScope,
292
+ detached: !!detached,
293
+ run(fn) {
294
+ if (!this.active) {
295
+ return;
296
+ }
297
+ const prevScope = activeEffectScope;
298
+ activeEffectScope = this;
299
+ try {
300
+ return fn();
301
+ } finally {
302
+ activeEffectScope = prevScope;
303
+ }
304
+ },
305
+ stop() {
306
+ if (!this.active) return;
307
+ this.active = false;
308
+ for (const effect2 of this.effects) {
309
+ try {
310
+ effect2.stop();
311
+ } catch (e) {
312
+ error(`Error stopping effect in scope: ${String(e)}`);
313
+ }
314
+ }
315
+ for (const cleanup of this.cleanups) {
316
+ try {
317
+ cleanup();
318
+ } catch (e) {
319
+ error(`Error running cleanup in scope: ${String(e)}`);
320
+ }
321
+ }
322
+ if (this.parent) {
323
+ const idx = this.parent.effects.indexOf(unsafeCast(this));
324
+ if (idx !== -1) {
325
+ this.parent.effects.splice(idx, 1);
326
+ }
327
+ }
328
+ this.effects.length = 0;
329
+ this.cleanups.length = 0;
330
+ this.parent = void 0;
331
+ }
332
+ };
333
+ if (!scope.detached && activeEffectScope) {
334
+ activeEffectScope.effects.push(unsafeCast(scope));
335
+ }
336
+ return scope;
337
+ }
338
+ function getCurrentScope() {
339
+ return activeEffectScope;
340
+ }
341
+ function onScopeDispose(fn) {
342
+ if (activeEffectScope) {
343
+ activeEffectScope.cleanups.push(fn);
344
+ }
345
+ }
281
346
  var activeEffect;
282
347
  var _trackDepth = 0;
283
348
  var targetMap = /* @__PURE__ */ new WeakMap();
@@ -338,7 +403,7 @@ function trackEffect(dep) {
338
403
  activeEffect.deps.push(dep);
339
404
  }
340
405
  }
341
- function trigger(target, type, key, _newValue, _oldValue) {
406
+ function trigger(target, type, key, newValue, oldValue) {
342
407
  const depsMap = targetMap.get(target);
343
408
  if (!depsMap) return;
344
409
  const deps = [];
@@ -372,9 +437,9 @@ function trigger(target, type, key, _newValue, _oldValue) {
372
437
  }
373
438
  }
374
439
  }
375
- triggerEffects([...new Set(effects)]);
440
+ triggerEffects([...new Set(effects)], target, type, key, newValue, oldValue);
376
441
  }
377
- function triggerEffects(effects) {
442
+ function triggerEffects(effects, target, type, key, newValue, oldValue) {
378
443
  if (triggerDepth > REACTIVITY_MAX_TRIGGER_DEPTH) {
379
444
  return;
380
445
  }
@@ -382,19 +447,19 @@ function triggerEffects(effects) {
382
447
  try {
383
448
  for (const effect2 of effects) {
384
449
  if (effect2.computed) {
385
- triggerEffect(effect2);
450
+ triggerEffect(effect2, target, type, key, newValue, oldValue);
386
451
  }
387
452
  }
388
453
  for (const effect2 of effects) {
389
454
  if (!effect2.computed) {
390
- triggerEffect(effect2);
455
+ triggerEffect(effect2, target, type, key, newValue, oldValue);
391
456
  }
392
457
  }
393
458
  } finally {
394
459
  triggerDepth--;
395
460
  }
396
461
  }
397
- function triggerEffect(effect2) {
462
+ function triggerEffect(effect2, target, type, key, newValue, oldValue) {
398
463
  if (effect2 !== activeEffect || effect2.allowRecurse) {
399
464
  if (effect2.scheduler) {
400
465
  effect2.scheduler();
@@ -412,6 +477,10 @@ var ReactiveEffect = class {
412
477
  this.parent = void 0;
413
478
  // 运行前清理(onEffectCleanup 注册的)
414
479
  this._cleanups = [];
480
+ const scope = getActiveEffectScope();
481
+ if (scope && scope.active) {
482
+ scope.effects.push(this);
483
+ }
415
484
  }
416
485
  run() {
417
486
  if (!this.active) {
@@ -707,9 +776,9 @@ function createMutableHandler(isReadonly2, isShallow) {
707
776
  const result = Reflect.set(target, key, value, receiver);
708
777
  if (target === toRaw(receiver)) {
709
778
  if (!hadKey) {
710
- trigger(target, TriggerOpTypes.ADD, key);
779
+ trigger(target, TriggerOpTypes.ADD, key, value);
711
780
  } else if (hasChanged(value, oldValue)) {
712
- trigger(target, TriggerOpTypes.SET, key);
781
+ trigger(target, TriggerOpTypes.SET, key, value, oldValue);
713
782
  }
714
783
  }
715
784
  return result;
@@ -719,10 +788,10 @@ function createMutableHandler(isReadonly2, isShallow) {
719
788
  return true;
720
789
  }
721
790
  const hadKey = hasOwn(target, key);
722
- Reflect.get(target, key);
791
+ const oldValue = Reflect.get(target, key);
723
792
  const result = Reflect.deleteProperty(target, key);
724
793
  if (result && hadKey) {
725
- trigger(target, TriggerOpTypes.DELETE, key);
794
+ trigger(target, TriggerOpTypes.DELETE, key, void 0, oldValue);
726
795
  }
727
796
  return result;
728
797
  },
@@ -784,7 +853,7 @@ function createCollectionHandler(isReadonly2, isShallow) {
784
853
  if (!hadKey || !Object.is(toRaw(oldValue), toRaw(args[1]))) {
785
854
  const triggerKey = toTriggerKey(args[0]);
786
855
  if (triggerKey !== void 0) {
787
- trigger(target, TriggerOpTypes.SET, triggerKey, args[1]);
856
+ trigger(target, TriggerOpTypes.SET, triggerKey, args[1], oldValue);
788
857
  }
789
858
  }
790
859
  return result2;
@@ -805,7 +874,7 @@ function createCollectionHandler(isReadonly2, isShallow) {
805
874
  if (hadKey) {
806
875
  const triggerKey = toTriggerKey(args[0]);
807
876
  if (triggerKey !== void 0) {
808
- trigger(target, TriggerOpTypes.DELETE, triggerKey);
877
+ trigger(target, TriggerOpTypes.DELETE, triggerKey, void 0, void 0);
809
878
  }
810
879
  trigger(target, TriggerOpTypes.DELETE, ITERATE_KEY);
811
880
  }
@@ -814,7 +883,7 @@ function createCollectionHandler(isReadonly2, isShallow) {
814
883
  const hadItems = rawTarget.size > 0;
815
884
  const result2 = res.apply(target, args);
816
885
  if (hadItems) {
817
- trigger(target, TriggerOpTypes.CLEAR, void 0);
886
+ trigger(target, TriggerOpTypes.CLEAR, void 0, void 0, void 0);
818
887
  }
819
888
  return result2;
820
889
  }
@@ -932,10 +1001,10 @@ var RefImpl = class {
932
1001
  const useDirectValue = this.__v_isShallow;
933
1002
  newVal = useDirectValue ? newVal : toRaw(newVal);
934
1003
  if (hasChanged(newVal, this._rawValue)) {
935
- this._rawValue;
1004
+ const oldVal = this._rawValue;
936
1005
  this._rawValue = newVal;
937
1006
  this._value = useDirectValue ? newVal : toReactive(newVal);
938
- triggerRefValue(this);
1007
+ triggerRefValue(this, newVal, oldVal);
939
1008
  }
940
1009
  }
941
1010
  };
@@ -954,10 +1023,10 @@ var ShallowRefImpl = class {
954
1023
  }
955
1024
  set value(newVal) {
956
1025
  if (hasChanged(newVal, this._rawValue)) {
957
- this._rawValue;
1026
+ const oldVal = this._rawValue;
958
1027
  this._rawValue = newVal;
959
1028
  this._value = newVal;
960
- triggerRefValue(this);
1029
+ triggerRefValue(this, newVal, oldVal);
961
1030
  }
962
1031
  }
963
1032
  };
@@ -967,7 +1036,7 @@ function trackRefValue(ref2) {
967
1036
  }
968
1037
  }
969
1038
  function triggerRefValue(ref2, newVal, oldVal) {
970
- trigger(ref2, TriggerOpTypes.SET, "value");
1039
+ trigger(ref2, TriggerOpTypes.SET, "value", newVal, oldVal);
971
1040
  }
972
1041
  function ref(value) {
973
1042
  if (isRef(value)) {
@@ -1538,6 +1607,6 @@ function _notifyDevToolsEffectRun(effectId) {
1538
1607
  return;
1539
1608
  }
1540
1609
 
1541
- export { ComputedRefSymbol, ReactiveSymbol, ReadonlySymbol, RefSymbol, ShallowRefSymbol, _notifyDevToolsEffectRun, _notifyDevToolsSignalChange, batch, batchAsync, batchScope, batchScopeAsync, batchScopeUntrack, computed2 as computed, computedSignal, customRef, effect, enableTracking, flushBatchScopes, getBatchScopeDepth, getCurrentBatchScopeStack, getSkippedTrackingCount, isComputedRef, isInBatchScope, isProxy, isReactive, isReadonly, isRef, isShallowRef, markRaw, onEffectCleanup, pauseTracking, reactive, readonly, readonlySignal, ref, resetSkippedTrackingCount, resetTracking, set, setSSRMode, shallowReactive, shallowReadonly, shallowRef, shouldSkipTracking, signal, signalBatch, computed as signalComputed, signalUntrack, stop, toRaw, toRef, toRefs, toValue, triggerRef, unref, untrack, update, valueOf, watch, watchEffect, watchPostEffect, watchSyncEffect, withFirstRenderOptimization, writableComputedSignal };
1610
+ export { ComputedRefSymbol, ReactiveSymbol, ReadonlySymbol, RefSymbol, ShallowRefSymbol, _notifyDevToolsEffectRun, _notifyDevToolsSignalChange, batch, batchAsync, batchScope, batchScopeAsync, batchScopeUntrack, computed2 as computed, computedSignal, customRef, effect, effectScope, enableTracking, flushBatchScopes, getBatchScopeDepth, getCurrentBatchScopeStack, getCurrentScope, getSkippedTrackingCount, isComputedRef, isInBatchScope, isProxy, isReactive, isReadonly, isRef, isShallowRef, markRaw, onEffectCleanup, onScopeDispose, pauseTracking, reactive, readonly, readonlySignal, ref, resetSkippedTrackingCount, resetTracking, set, setSSRMode, shallowReactive, shallowReadonly, shallowRef, shouldSkipTracking, signal, signalBatch, computed as signalComputed, signalUntrack, stop, toRaw, toRef, toRefs, toValue, triggerRef, unref, untrack, update, valueOf, watch, watchEffect, watchPostEffect, watchSyncEffect, withFirstRenderOptimization, writableComputedSignal };
1542
1611
  //# sourceMappingURL=index.mjs.map
1543
1612
  //# sourceMappingURL=index.mjs.map