@zeus-js/signal 0.1.1-beta.0 → 0.1.1-beta.2

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * signal v0.1.1-beta.0
2
+ * signal v0.1.1-beta.2
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -28,6 +28,57 @@ let ReactiveFlags = /* @__PURE__ */ function(ReactiveFlags) {
28
28
  return ReactiveFlags;
29
29
  }({});
30
30
  //#endregion
31
+ //#region packages/core/signal/src/runtime-diagnostics.ts
32
+ let activeRuntimeDiagnostics;
33
+ function runWithRuntimeDiagnostics(diagnostics, fn) {
34
+ if (!(diagnostics === null || diagnostics === void 0 ? void 0 : diagnostics[0])) return fn();
35
+ const previous = activeRuntimeDiagnostics;
36
+ activeRuntimeDiagnostics = diagnostics;
37
+ try {
38
+ return fn();
39
+ } finally {
40
+ activeRuntimeDiagnostics = (previous === null || previous === void 0 ? void 0 : previous[0]) ? previous : void 0;
41
+ }
42
+ }
43
+ function createRuntimeDiagnosticsSession() {
44
+ const diagnostics = [
45
+ true,
46
+ 0,
47
+ 0,
48
+ 0,
49
+ 0,
50
+ 0,
51
+ 0,
52
+ 0,
53
+ (run) => () => runWithRuntimeDiagnostics(diagnostics, run),
54
+ (run) => (fn) => runWithRuntimeDiagnostics(diagnostics, () => run(fn))
55
+ ];
56
+ return {
57
+ run(fn) {
58
+ return runWithRuntimeDiagnostics(diagnostics, fn);
59
+ },
60
+ snapshot() {
61
+ const allocationsCreated = diagnostics[1] + diagnostics[3] + diagnostics[4] + diagnostics[6] + diagnostics[7];
62
+ const allocationsDisposed = diagnostics[2] + diagnostics[5];
63
+ return {
64
+ effectsCreated: diagnostics[1],
65
+ effectsDisposed: diagnostics[2],
66
+ proxiesCreated: diagnostics[3],
67
+ scopesCreated: diagnostics[4],
68
+ scopesDisposed: diagnostics[5],
69
+ refsCreated: diagnostics[6],
70
+ memosCreated: diagnostics[7],
71
+ allocationsCreated,
72
+ allocationsDisposed
73
+ };
74
+ },
75
+ dispose() {
76
+ diagnostics[0] = false;
77
+ if (activeRuntimeDiagnostics === diagnostics) activeRuntimeDiagnostics = void 0;
78
+ }
79
+ };
80
+ }
81
+ //#endregion
31
82
  //#region packages/core/signal/src/warning.ts
32
83
  function warn(msg, ...args) {
33
84
  console.warn(`[Zeus warn] ${msg}`, ...args);
@@ -45,12 +96,27 @@ var EffectScope = class {
45
96
  this._isPaused = false;
46
97
  this._warnOnRun = true;
47
98
  this.__v_skip = true;
99
+ const diagnostics = activeRuntimeDiagnostics;
100
+ if (diagnostics) {
101
+ diagnostics[4]++;
102
+ this.run = diagnostics[9](this.run.bind(this));
103
+ const stop = this.stop.bind(this);
104
+ this.stop = (fromParent) => {
105
+ const active = this._active;
106
+ try {
107
+ stop(fromParent);
108
+ } finally {
109
+ if (active && !this._active && diagnostics[0]) diagnostics[5]++;
110
+ }
111
+ };
112
+ }
48
113
  if (!detached && activeEffectScope) if (activeEffectScope.active) {
49
114
  this.parent = activeEffectScope;
50
115
  this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
51
116
  } else {
52
117
  this._active = false;
53
118
  this._warnOnRun = false;
119
+ if (diagnostics) diagnostics[5]++;
54
120
  }
55
121
  }
56
122
  get active() {
@@ -199,9 +265,23 @@ var ReactiveEffect = class {
199
265
  this.next = void 0;
200
266
  this.cleanups = void 0;
201
267
  this.scheduler = void 0;
268
+ const diagnostics = activeRuntimeDiagnostics;
269
+ if (diagnostics) {
270
+ diagnostics[1]++;
271
+ this.run = diagnostics[8](this.run.bind(this));
272
+ const stop = this.stop.bind(this);
273
+ this.stop = () => {
274
+ const active = !!(this.flags & 1);
275
+ stop();
276
+ if (active && !(this.flags & 1) && diagnostics[0]) diagnostics[2]++;
277
+ };
278
+ }
202
279
  this.scope = activeEffectScope;
203
280
  if (activeEffectScope) if (activeEffectScope.active) activeEffectScope.effects.push(this);
204
- else this.flags &= -2;
281
+ else {
282
+ this.flags &= -2;
283
+ if (diagnostics) diagnostics[2]++;
284
+ }
205
285
  }
206
286
  pause() {
207
287
  this.flags |= 64;
@@ -744,6 +824,8 @@ var ComputedRefImpl = class {
744
824
  this.flags = 16;
745
825
  this.globalVersion = globalVersion - 1;
746
826
  this.next = void 0;
827
+ const diagnostics = activeRuntimeDiagnostics;
828
+ if (diagnostics) diagnostics[7]++;
747
829
  this["__v_isReadonly"] = !setter;
748
830
  this.isSSR = isSSR;
749
831
  }
@@ -1325,6 +1407,8 @@ function createReactiveObject(target, isReadonly, baseHandlers, collectionHandle
1325
1407
  if (existingProxy) return existingProxy;
1326
1408
  const proxy = new Proxy(target, targetType === 2 ? collectionHandlers : baseHandlers);
1327
1409
  proxyMap.set(target, proxy);
1410
+ const diagnostics = activeRuntimeDiagnostics;
1411
+ if (diagnostics) diagnostics[3]++;
1328
1412
  return proxy;
1329
1413
  }
1330
1414
  /**
@@ -1453,6 +1537,8 @@ var RefImpl = class {
1453
1537
  this.dep = new Dep();
1454
1538
  this[_ReactiveFlags$IS_REF] = true;
1455
1539
  this[_ReactiveFlags$IS_SHA] = false;
1540
+ const diagnostics = activeRuntimeDiagnostics;
1541
+ if (diagnostics) diagnostics[6]++;
1456
1542
  this._rawValue = isShallow ? value : /* @__PURE__ */ toRaw(value);
1457
1543
  this._value = isShallow ? value : toReactive(value);
1458
1544
  this["__v_isShallow"] = isShallow;
@@ -1522,6 +1608,9 @@ function state(value) {
1522
1608
  if (arguments.length === 0) return /* @__PURE__ */ ref();
1523
1609
  return isProxyable(value) ? /* @__PURE__ */ reactive(value) : /* @__PURE__ */ ref(value);
1524
1610
  }
1611
+ function shallowState(value) {
1612
+ return arguments.length === 0 ? /* @__PURE__ */ shallowRef() : /* @__PURE__ */ shallowRef(value);
1613
+ }
1525
1614
  function isValueState(value) {
1526
1615
  if (!value || typeof value !== "object") return false;
1527
1616
  const obj = value;
@@ -1733,4 +1822,4 @@ function traverse(value, depth = Infinity, seen) {
1733
1822
  return value;
1734
1823
  }
1735
1824
  //#endregion
1736
- export { ARRAY_ITERATE_KEY, EffectFlags, EffectScope, ITERATE_KEY, MAP_KEY_ITERATE_KEY, ReactiveEffect, ReactiveFlags, TrackOpTypes, TriggerOpTypes, WatchErrorCodes, batch, computed, createEffect, createMemo, createRoot, createSignal, effect, effectScope, effectScope as scope, enableTracking, flushJobs, getCurrentEffect, getCurrentScope, getCurrentWatcher, isValueState, nextTick, onCleanup, onEffectCleanup, onScopeDispose, onWatcherCleanup, pauseTracking, queueJob, reactiveReadArray, resetTracking, shallowReadArray, state, stop, track, traverse, trigger, untrack, watch };
1825
+ export { ARRAY_ITERATE_KEY, EffectFlags, EffectScope, ITERATE_KEY, MAP_KEY_ITERATE_KEY, ReactiveEffect, ReactiveFlags, TrackOpTypes, TriggerOpTypes, WatchErrorCodes, batch, computed, createEffect, createMemo, createRoot, createRuntimeDiagnosticsSession, createSignal, effect, effectScope, effectScope as scope, enableTracking, flushJobs, getCurrentEffect, getCurrentScope, getCurrentWatcher, isValueState, nextTick, onCleanup, onEffectCleanup, onScopeDispose, onWatcherCleanup, pauseTracking, queueJob, reactiveReadArray, resetTracking, shallowReadArray, shallowState, state, stop, track, traverse, trigger, untrack, watch };