signalium 2.3.2 → 3.0.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.
Files changed (130) hide show
  1. package/CHANGELOG.md +230 -0
  2. package/dist/cjs/development/component-shared-Cug2Y5YZ.js +33 -0
  3. package/dist/cjs/development/component-shared-Cug2Y5YZ.js.map +1 -0
  4. package/dist/cjs/development/{debug-ouT0N0E4.js → debug-C46WDxhL.js} +47 -195
  5. package/dist/cjs/development/debug-C46WDxhL.js.map +1 -0
  6. package/dist/cjs/development/debug.js +1 -1
  7. package/dist/cjs/development/index.js +3 -2
  8. package/dist/cjs/development/index.js.map +1 -1
  9. package/dist/cjs/development/react/index.js +256 -87
  10. package/dist/cjs/development/react/index.js.map +1 -1
  11. package/dist/cjs/development/react/index.server.js +14 -0
  12. package/dist/cjs/development/react/index.server.js.map +1 -0
  13. package/dist/cjs/development/react/server.js +37 -0
  14. package/dist/cjs/development/react/server.js.map +1 -0
  15. package/dist/cjs/development/{snapshot-BPJ-qw6l.js → snapshot-48aGePMZ.js} +2 -2
  16. package/dist/cjs/development/{snapshot-BPJ-qw6l.js.map → snapshot-48aGePMZ.js.map} +1 -1
  17. package/dist/cjs/development/transform/index.js +196 -13
  18. package/dist/cjs/development/transform/index.js.map +1 -1
  19. package/dist/cjs/development/utils.js +6 -6
  20. package/dist/cjs/development/utils.js.map +1 -1
  21. package/dist/cjs/production/component-shared-D0J85PUi.js +33 -0
  22. package/dist/cjs/production/component-shared-D0J85PUi.js.map +1 -0
  23. package/dist/cjs/production/{contexts-DtQMtXO7.js → contexts-CM3QLfV8.js} +47 -198
  24. package/dist/cjs/production/contexts-CM3QLfV8.js.map +1 -0
  25. package/dist/cjs/production/debug.js +1 -1
  26. package/dist/cjs/production/index.js +3 -2
  27. package/dist/cjs/production/index.js.map +1 -1
  28. package/dist/cjs/production/react/index.js +242 -89
  29. package/dist/cjs/production/react/index.js.map +1 -1
  30. package/dist/cjs/production/react/index.server.js +14 -0
  31. package/dist/cjs/production/react/index.server.js.map +1 -0
  32. package/dist/cjs/production/react/server.js +37 -0
  33. package/dist/cjs/production/react/server.js.map +1 -0
  34. package/dist/cjs/production/{snapshot-Dw62eSpw.js → snapshot-BCESZVAP.js} +2 -2
  35. package/dist/cjs/production/{snapshot-Dw62eSpw.js.map → snapshot-BCESZVAP.js.map} +1 -1
  36. package/dist/cjs/production/transform/index.js +196 -13
  37. package/dist/cjs/production/transform/index.js.map +1 -1
  38. package/dist/cjs/production/utils.js +6 -6
  39. package/dist/cjs/production/utils.js.map +1 -1
  40. package/dist/esm/development/component-shared-CLSmdnGU.js +34 -0
  41. package/dist/esm/development/component-shared-CLSmdnGU.js.map +1 -0
  42. package/dist/esm/development/{debug-DaK9qsbI.js → debug-BTLbgTPK.js} +79 -227
  43. package/dist/esm/development/debug-BTLbgTPK.js.map +1 -0
  44. package/dist/esm/development/debug.js +9 -9
  45. package/dist/esm/development/index.js +14 -13
  46. package/dist/esm/development/react/index.js +232 -79
  47. package/dist/esm/development/react/index.js.map +1 -1
  48. package/dist/esm/development/react/index.server.js +14 -0
  49. package/dist/esm/development/react/index.server.js.map +1 -0
  50. package/dist/esm/development/react/server.js +20 -0
  51. package/dist/esm/development/react/server.js.map +1 -0
  52. package/dist/esm/development/{snapshot-D8ZJEbwO.js → snapshot-Ca_rQa4c.js} +2 -2
  53. package/dist/esm/development/{snapshot-D8ZJEbwO.js.map → snapshot-Ca_rQa4c.js.map} +1 -1
  54. package/dist/esm/development/transform/index.js +197 -14
  55. package/dist/esm/development/transform/index.js.map +1 -1
  56. package/dist/esm/development/utils.js +11 -11
  57. package/dist/esm/development/utils.js.map +1 -1
  58. package/dist/esm/index.d.ts +2 -2
  59. package/dist/esm/index.d.ts.map +1 -1
  60. package/dist/esm/internals/async.d.ts +3 -3
  61. package/dist/esm/internals/async.d.ts.map +1 -1
  62. package/dist/esm/internals/contexts.d.ts +10 -6
  63. package/dist/esm/internals/contexts.d.ts.map +1 -1
  64. package/dist/esm/internals/core-api.d.ts +2 -2
  65. package/dist/esm/internals/core-api.d.ts.map +1 -1
  66. package/dist/esm/internals/get.d.ts.map +1 -1
  67. package/dist/esm/internals/reactive.d.ts +3 -9
  68. package/dist/esm/internals/reactive.d.ts.map +1 -1
  69. package/dist/esm/internals/scheduling.d.ts +0 -2
  70. package/dist/esm/internals/scheduling.d.ts.map +1 -1
  71. package/dist/esm/internals/watch.d.ts +3 -4
  72. package/dist/esm/internals/watch.d.ts.map +1 -1
  73. package/dist/esm/production/component-shared-Dva0S5e3.js +34 -0
  74. package/dist/esm/production/component-shared-Dva0S5e3.js.map +1 -0
  75. package/dist/esm/production/{contexts-US_h2nBi.js → contexts-FxCndlvf.js} +71 -222
  76. package/dist/esm/production/contexts-FxCndlvf.js.map +1 -0
  77. package/dist/esm/production/debug.js +1 -1
  78. package/dist/esm/production/index.js +14 -13
  79. package/dist/esm/production/react/index.js +219 -82
  80. package/dist/esm/production/react/index.js.map +1 -1
  81. package/dist/esm/production/react/index.server.js +14 -0
  82. package/dist/esm/production/react/index.server.js.map +1 -0
  83. package/dist/esm/production/react/server.js +20 -0
  84. package/dist/esm/production/react/server.js.map +1 -0
  85. package/dist/esm/production/{snapshot-CfJGJCvW.js → snapshot-TYiTYPGB.js} +2 -2
  86. package/dist/esm/production/{snapshot-CfJGJCvW.js.map → snapshot-TYiTYPGB.js.map} +1 -1
  87. package/dist/esm/production/transform/index.js +197 -14
  88. package/dist/esm/production/transform/index.js.map +1 -1
  89. package/dist/esm/production/utils.js +11 -11
  90. package/dist/esm/production/utils.js.map +1 -1
  91. package/dist/esm/react/async-component.d.ts +42 -0
  92. package/dist/esm/react/async-component.d.ts.map +1 -0
  93. package/dist/esm/react/component-server.d.ts +4 -0
  94. package/dist/esm/react/component-server.d.ts.map +1 -0
  95. package/dist/esm/react/component-shared.d.ts +21 -0
  96. package/dist/esm/react/component-shared.d.ts.map +1 -0
  97. package/dist/esm/react/component.d.ts +5 -1
  98. package/dist/esm/react/component.d.ts.map +1 -1
  99. package/dist/esm/react/index.d.ts +3 -4
  100. package/dist/esm/react/index.d.ts.map +1 -1
  101. package/dist/esm/react/index.server.d.ts +8 -0
  102. package/dist/esm/react/index.server.d.ts.map +1 -0
  103. package/dist/esm/react/pause-signals-context.d.ts +18 -0
  104. package/dist/esm/react/pause-signals-context.d.ts.map +1 -0
  105. package/dist/esm/react/server.d.ts +12 -0
  106. package/dist/esm/react/server.d.ts.map +1 -0
  107. package/dist/esm/react/use-reactive.d.ts +36 -7
  108. package/dist/esm/react/use-reactive.d.ts.map +1 -1
  109. package/dist/esm/transform/async.d.ts.map +1 -1
  110. package/dist/esm/transform/callback.d.ts.map +1 -1
  111. package/dist/esm/transform/index.d.ts +1 -0
  112. package/dist/esm/transform/index.d.ts.map +1 -1
  113. package/dist/esm/transform/preset.d.ts +1 -0
  114. package/dist/esm/transform/preset.d.ts.map +1 -1
  115. package/dist/esm/transform/use-reactive.d.ts +9 -0
  116. package/dist/esm/transform/use-reactive.d.ts.map +1 -0
  117. package/dist/esm/types.d.ts +33 -10
  118. package/dist/esm/types.d.ts.map +1 -1
  119. package/dist/esm/utils.d.ts +2 -2
  120. package/dist/esm/utils.d.ts.map +1 -1
  121. package/package.json +35 -4
  122. package/react-server.js +15 -0
  123. package/dist/cjs/development/debug-ouT0N0E4.js.map +0 -1
  124. package/dist/cjs/production/contexts-DtQMtXO7.js.map +0 -1
  125. package/dist/esm/development/debug-DaK9qsbI.js.map +0 -1
  126. package/dist/esm/internals/weakref.d.ts +0 -3
  127. package/dist/esm/internals/weakref.d.ts.map +0 -1
  128. package/dist/esm/production/contexts-US_h2nBi.js.map +0 -1
  129. package/dist/esm/react/suspend-signals-context.d.ts +0 -3
  130. package/dist/esm/react/suspend-signals-context.d.ts.map +0 -1
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ const contexts = require("./contexts-CM3QLfV8.js");
3
+ function isGeneratorFunction(fn) {
4
+ return typeof fn === "function" && fn.constructor?.name === "GeneratorFunction";
5
+ }
6
+ function isAsyncFunctionWithoutTransform(fn) {
7
+ return typeof fn === "function" && fn.constructor?.name === "AsyncFunction";
8
+ }
9
+ function createServerAsyncComponentWrapper(fn) {
10
+ return async function(props) {
11
+ const scope = contexts.getCurrentScope();
12
+ const owned = contexts.createReactiveSignal({ compute: () => null, equals: () => true, isRelay: false, tracer: void 0 }, [], void 0, scope);
13
+ return contexts.generatorResultToPromiseWithConsumer(fn(props), owned);
14
+ };
15
+ }
16
+ function createServerSyncComponentWrapper(fn) {
17
+ return function(props) {
18
+ const scope = contexts.getCurrentScope();
19
+ const owned = contexts.createReactiveSignal({ compute: () => null, equals: () => true, isRelay: false, tracer: void 0 }, [], void 0, scope);
20
+ const prevConsumer = contexts.getCurrentConsumer();
21
+ try {
22
+ contexts.setCurrentConsumer(owned);
23
+ return fn(props);
24
+ } finally {
25
+ contexts.setCurrentConsumer(prevConsumer);
26
+ }
27
+ };
28
+ }
29
+ exports.createServerAsyncComponentWrapper = createServerAsyncComponentWrapper;
30
+ exports.createServerSyncComponentWrapper = createServerSyncComponentWrapper;
31
+ exports.isAsyncFunctionWithoutTransform = isAsyncFunctionWithoutTransform;
32
+ exports.isGeneratorFunction = isGeneratorFunction;
33
+ //# sourceMappingURL=component-shared-D0J85PUi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-shared-D0J85PUi.js","sources":["../../../.tsc-out/react/component-shared.js"],"sourcesContent":["import { getCurrentConsumer, setCurrentConsumer } from '../internals/consumer.js';\nimport { getCurrentScope } from '../internals/contexts.js';\nimport { createReactiveSignal } from '../internals/reactive.js';\nimport { generatorResultToPromiseWithConsumer } from '../internals/generators.js';\nexport function isGeneratorFunction(fn) {\n return (typeof fn === 'function' && fn.constructor?.name === 'GeneratorFunction');\n}\nexport function isAsyncFunctionWithoutTransform(fn) {\n return typeof fn === 'function' && fn.constructor?.name === 'AsyncFunction';\n}\n/**\n * Wrap a Babel-transformed async generator in a real `async function` that drives it\n * with {@link generatorResultToPromiseWithConsumer}. Used on the server (RSC + SSR)\n * where hooks-based Suspense replay is not appropriate.\n */\nexport function createServerAsyncComponentWrapper(fn) {\n return async function (props) {\n const scope = getCurrentScope();\n const owned = createReactiveSignal({ compute: () => null, equals: () => true, isRelay: false, tracer: undefined }, [], undefined, scope);\n return generatorResultToPromiseWithConsumer(fn(props), owned);\n };\n}\n/**\n * Wrap a sync render function with consumer/scope tracking. Used by the server\n * `component()` for non-generator definitions.\n */\nexport function createServerSyncComponentWrapper(fn) {\n return function (props) {\n const scope = getCurrentScope();\n const owned = createReactiveSignal({ compute: () => null, equals: () => true, isRelay: false, tracer: undefined }, [], undefined, scope);\n const prevConsumer = getCurrentConsumer();\n try {\n setCurrentConsumer(owned);\n return fn(props);\n }\n finally {\n setCurrentConsumer(prevConsumer);\n }\n };\n}\n"],"names":["getCurrentScope","createReactiveSignal","generatorResultToPromiseWithConsumer","getCurrentConsumer","setCurrentConsumer"],"mappings":";;AAIO,SAAS,oBAAoB,IAAI;AACpC,SAAQ,OAAO,OAAO,cAAc,GAAG,aAAa,SAAS;AACjE;AACO,SAAS,gCAAgC,IAAI;AAChD,SAAO,OAAO,OAAO,cAAc,GAAG,aAAa,SAAS;AAChE;AAMO,SAAS,kCAAkC,IAAI;AAClD,SAAO,eAAgB,OAAO;AAC1B,UAAM,QAAQA,SAAAA,gBAAe;AAC7B,UAAM,QAAQC,SAAAA,qBAAqB,EAAE,SAAS,MAAM,MAAM,QAAQ,MAAM,MAAM,SAAS,OAAO,QAAQ,OAAS,GAAI,CAAA,GAAI,QAAW,KAAK;AACvI,WAAOC,8CAAqC,GAAG,KAAK,GAAG,KAAK;AAAA,EAChE;AACJ;AAKO,SAAS,iCAAiC,IAAI;AACjD,SAAO,SAAU,OAAO;AACpB,UAAM,QAAQF,SAAAA,gBAAe;AAC7B,UAAM,QAAQC,SAAAA,qBAAqB,EAAE,SAAS,MAAM,MAAM,QAAQ,MAAM,MAAM,SAAS,OAAO,QAAQ,OAAS,GAAI,CAAA,GAAI,QAAW,KAAK;AACvI,UAAM,eAAeE,SAAAA,mBAAkB;AACvC,QAAI;AACAC,eAAAA,mBAAmB,KAAK;AACxB,aAAO,GAAG,KAAK;AAAA,IACnB,UACR;AACYA,eAAAA,mBAAmB,YAAY;AAAA,IACnC;AAAA,EACJ;AACJ;;;;;"}
@@ -1,15 +1,5 @@
1
1
  "use strict";
2
2
  const config = require("./config-B0MtLBgx.js");
3
- class WeakRefPolyfill {
4
- value;
5
- constructor(value) {
6
- this.value = value;
7
- }
8
- deref() {
9
- return this.value;
10
- }
11
- }
12
- const WeakRef$1 = typeof WeakRef === "function" ? WeakRef : WeakRefPolyfill;
13
3
  let CURRENT_CONSUMER;
14
4
  const setCurrentConsumer = (consumer) => {
15
5
  CURRENT_CONSUMER = consumer;
@@ -98,34 +88,19 @@ function signal(initialValue, opts) {
98
88
  const notifier = (opts) => {
99
89
  return new StateSignal(void 0, FALSE_EQUALS, opts?.desc);
100
90
  };
101
- function watchSignal(signal2, parentIsSuspended) {
102
- if (parentIsSuspended) {
103
- watchSuspendedSignal(signal2);
104
- } else {
105
- watchActiveSignal(signal2);
106
- }
107
- }
108
- function unwatchSignal(signal2, parentIsSuspended) {
109
- if (parentIsSuspended) {
110
- unwatchSuspendedSignal(signal2);
111
- } else {
112
- unwatchActiveSignal(signal2);
113
- }
114
- }
115
- function watchActiveSignal(signal2) {
91
+ function watchSignal(signal2) {
116
92
  const { watchCount } = signal2;
117
- const newWatchCount = watchCount + 1;
118
- signal2.watchCount = newWatchCount;
93
+ signal2.watchCount = watchCount + 1;
119
94
  cancelDeactivate(signal2);
120
95
  if (signal2._isActive) {
121
96
  return;
122
97
  }
123
98
  for (const dep of signal2.deps.keys()) {
124
- watchActiveSignal(dep);
99
+ watchSignal(dep);
125
100
  }
126
101
  activateSignal(signal2);
127
102
  }
128
- function unwatchActiveSignal(signal2) {
103
+ function unwatchSignal(signal2) {
129
104
  const { watchCount } = signal2;
130
105
  const newWatchCount = Math.max(watchCount - 1, 0);
131
106
  signal2.watchCount = newWatchCount;
@@ -133,51 +108,7 @@ function unwatchActiveSignal(signal2) {
133
108
  scheduleDeactivate(signal2);
134
109
  }
135
110
  }
136
- function watchSuspendedSignal(signal2) {
137
- const { watchCount, suspendCount } = signal2;
138
- const newWatchCount = watchCount + 1;
139
- const newSuspendCount = suspendCount + 1;
140
- signal2.watchCount = newWatchCount;
141
- signal2.suspendCount = newSuspendCount;
142
- cancelDeactivate(signal2);
143
- if (watchCount === 0) {
144
- for (const dep of signal2.deps.keys()) {
145
- watchSuspendedSignal(dep);
146
- }
147
- }
148
- }
149
- function unwatchSuspendedSignal(signal2) {
150
- const { watchCount, suspendCount } = signal2;
151
- const newWatchCount = Math.max(watchCount - 1, 0);
152
- const newSuspendCount = Math.max(suspendCount - 1, 0);
153
- signal2.watchCount = newWatchCount;
154
- signal2.suspendCount = newSuspendCount;
155
- if (newWatchCount === 0) {
156
- scheduleDeactivate(signal2);
157
- }
158
- }
159
- function resumeSignal(signal2) {
160
- const { watchCount, suspendCount } = signal2;
161
- const newSuspendCount = Math.max(suspendCount - 1, 0);
162
- signal2.suspendCount = newSuspendCount;
163
- cancelDeactivate(signal2);
164
- if (watchCount > 0 && !signal2._isActive) {
165
- for (const dep of signal2.deps.keys()) {
166
- resumeSignal(dep);
167
- }
168
- activateSignal(signal2);
169
- }
170
- }
171
- function suspendSignal(signal2) {
172
- const { watchCount, suspendCount } = signal2;
173
- const newSuspendCount = suspendCount + 1;
174
- signal2.suspendCount = newSuspendCount;
175
- if (watchCount > 0 && newSuspendCount === watchCount) {
176
- scheduleDeactivate(signal2);
177
- }
178
- }
179
111
  function activateSignal(signal2) {
180
- signal2.scope?.removeFromGc(signal2);
181
112
  cancelDeactivate(signal2);
182
113
  signal2._isActive = true;
183
114
  if (isRelay(signal2)) {
@@ -185,37 +116,22 @@ function activateSignal(signal2) {
185
116
  }
186
117
  }
187
118
  function deactivateSignal(signal2) {
188
- const { watchCount, suspendCount } = signal2;
189
119
  signal2._isActive = false;
190
- const isSuspending = watchCount > 0 && suspendCount === watchCount;
191
120
  for (const dep of signal2.deps.keys()) {
192
- const { watchCount: depWatchCount, suspendCount: depSuspendCount } = dep;
193
- if (isSuspending) {
194
- const newSuspendCount = dep.suspendCount = depSuspendCount + 1;
195
- if (newSuspendCount === depWatchCount) {
196
- deactivateSignal(dep);
197
- }
198
- } else {
199
- const newWatchCount = dep.watchCount = depWatchCount - 1;
200
- if (newWatchCount === 0) {
201
- deactivateSignal(dep);
202
- }
121
+ const newWatchCount = Math.max(dep.watchCount - 1, 0);
122
+ dep.watchCount = newWatchCount;
123
+ if (newWatchCount === 0) {
124
+ deactivateSignal(dep);
203
125
  }
204
126
  }
205
127
  if (isRelay(signal2)) {
206
128
  signal2._value?.();
207
129
  }
208
- if (watchCount === 0) {
209
- signal2.scope?.markForGc(signal2);
210
- signal2.reset();
211
- }
212
130
  }
213
- const scheduleIdleCallback = typeof requestIdleCallback === "function" ? requestIdleCallback : (cb) => config.scheduleFlush(cb);
214
131
  let PENDING_PULLS = /* @__PURE__ */ new Set();
215
132
  let PENDING_ASYNC_PULLS = [];
216
133
  let PENDING_DEACTIVE = /* @__PURE__ */ new Set();
217
134
  let PENDING_LISTENERS = [];
218
- let PENDING_GC = /* @__PURE__ */ new Set();
219
135
  const microtask = () => Promise.resolve();
220
136
  let currentFlush = null;
221
137
  const scheduleFlush = (fn) => {
@@ -242,7 +158,6 @@ const scheduleDeactivate = (signal2) => {
242
158
  scheduleFlush();
243
159
  };
244
160
  const cancelDeactivate = (signal2) => {
245
- signal2.scope?.removeFromGc(signal2);
246
161
  PENDING_DEACTIVE.delete(signal2);
247
162
  };
248
163
  const scheduleListeners = (signal2) => {
@@ -251,17 +166,6 @@ const scheduleListeners = (signal2) => {
251
166
  };
252
167
  const scheduleTracer = (tracer) => {
253
168
  };
254
- const scheduleGcSweep = (scope) => {
255
- PENDING_GC.add(scope);
256
- if (PENDING_GC.size > 1)
257
- return;
258
- scheduleIdleCallback(() => {
259
- for (const scope2 of PENDING_GC) {
260
- scope2.sweepGc();
261
- }
262
- PENDING_GC.clear();
263
- });
264
- };
265
169
  const flushWatchers = async () => {
266
170
  const flush = currentFlush;
267
171
  if (!flush)
@@ -320,7 +224,7 @@ function propagateDirty(signal2) {
320
224
  scheduleAsyncPull(signal2);
321
225
  }
322
226
  } else {
323
- if (signal2._isListener && !signal2._isSuspendedListener) {
227
+ if (signal2._isListener && signal2.watchCount > 0) {
324
228
  schedulePull(signal2);
325
229
  }
326
230
  dirtySignalConsumers(signal2.subs);
@@ -421,6 +325,9 @@ function isGeneratorResult(value) {
421
325
  function isPromise(value) {
422
326
  return value.constructor === Promise;
423
327
  }
328
+ function isThennable(value) {
329
+ return value !== null && typeof value === "object" && typeof value.then === "function";
330
+ }
424
331
  function generatorResultToPromiseWithConsumer(generator, savedConsumer) {
425
332
  function adopt(value) {
426
333
  return typeof value === "object" && value !== null && (isPromise(value) || isReactivePromise(value)) ? value : Promise.resolve(value);
@@ -539,12 +446,6 @@ function callback(fn, idx, deps) {
539
446
  }
540
447
  return callback2.fn;
541
448
  }
542
- function isAbortError(error) {
543
- if (typeof DOMException !== "undefined" && error instanceof DOMException) {
544
- return error.name === "AbortError";
545
- }
546
- return error instanceof Error && error.name === "AbortError";
547
- }
548
449
  const arrayFrom = Array.from;
549
450
  function isThenable(v) {
550
451
  return v !== null && typeof v === "object" && typeof v.then === "function";
@@ -857,10 +758,6 @@ class ReactivePromiseImpl {
857
758
  }
858
759
  }
859
760
  _setError(nextError, awaitSubs = this._awaitSubs) {
860
- if (nextError !== this._error && !isAbortError(nextError)) {
861
- const desc = this._signal?.desc ?? void 0;
862
- console.error(`[signalium] Unhandled async error${desc ? ` in "${desc}"` : ""}:`, nextError);
863
- }
864
761
  let error = this._error;
865
762
  let notifyFlags = 0;
866
763
  if (error !== nextError) {
@@ -1016,9 +913,6 @@ function setReactivePromise(value) {
1016
913
  function isReactivePromise(value) {
1017
914
  return REACTIVE_PROMISE_SET.has(value);
1018
915
  }
1019
- function isRelay$1(obj) {
1020
- return isReactivePromise(obj) && (obj["_flags"] & 128) !== 0;
1021
- }
1022
916
  function createPromise(promise, signal2) {
1023
917
  const p = new ReactivePromiseImpl();
1024
918
  p["_signal"] = signal2;
@@ -1119,7 +1013,7 @@ function getSignal(signal2) {
1119
1013
  if (prevConsumedAt !== computedCount) {
1120
1014
  if (prevEdge === void 0) {
1121
1015
  if (currentConsumer.watchCount > 0) {
1122
- watchSignal(signal2, currentConsumer._isSuspended);
1016
+ watchSignal(signal2);
1123
1017
  }
1124
1018
  }
1125
1019
  const updatedAt = checkSignal(signal2);
@@ -1226,12 +1120,15 @@ function runSignal(signal2) {
1226
1120
  }
1227
1121
  }
1228
1122
  function disconnectSignal(signal2, computedCount = signal2.computedCount) {
1229
- const { ref, deps, _isSuspended: isSuspended } = signal2;
1123
+ const { ref, deps } = signal2;
1230
1124
  for (const [dep, edge] of deps) {
1231
1125
  if (edge.consumedAt !== computedCount) {
1232
- unwatchSignal(dep, isSuspended);
1126
+ unwatchSignal(dep);
1233
1127
  dep.subs.delete(ref);
1234
1128
  deps.delete(dep);
1129
+ if (dep._state < 2) {
1130
+ dep._state = 2;
1131
+ }
1235
1132
  }
1236
1133
  }
1237
1134
  }
@@ -1515,12 +1412,11 @@ class ReactiveSignal {
1515
1412
  id = ++ID;
1516
1413
  subs = /* @__PURE__ */ new Map();
1517
1414
  deps = /* @__PURE__ */ new Map();
1518
- ref = new WeakRef$1(this);
1415
+ ref = new WeakRef(this);
1519
1416
  dirtyHead = void 0;
1520
1417
  updatedCount = 0;
1521
1418
  computedCount = 0;
1522
1419
  watchCount = 0;
1523
- suspendCount = 0;
1524
1420
  key;
1525
1421
  args;
1526
1422
  callbacks = void 0;
@@ -1547,31 +1443,24 @@ class ReactiveSignal {
1547
1443
  get _isListener() {
1548
1444
  return (this.flags & 16) !== 0;
1549
1445
  }
1550
- get _isSuspendedListener() {
1551
- return (this.flags & 32) !== 0;
1552
- }
1553
- get _isSuspended() {
1554
- const { watchCount, suspendCount } = this;
1555
- return watchCount > 0 && watchCount === suspendCount;
1556
- }
1557
1446
  get _isActive() {
1558
- return (this.flags & 64) !== 0;
1447
+ return (this.flags & 32) !== 0;
1559
1448
  }
1560
1449
  set _isActive(isActive) {
1561
1450
  if (isActive) {
1562
- this.flags |= 64;
1451
+ this.flags |= 32;
1563
1452
  } else {
1564
- this.flags &= -65;
1453
+ this.flags &= -33;
1565
1454
  }
1566
1455
  }
1567
1456
  get _isLazy() {
1568
- return (this.flags & 128) !== 0;
1457
+ return (this.flags & 64) !== 0;
1569
1458
  }
1570
1459
  set _isLazy(isLazy) {
1571
1460
  if (isLazy) {
1572
- this.flags |= 128;
1461
+ this.flags |= 64;
1573
1462
  } else {
1574
- this.flags &= -129;
1463
+ this.flags &= -65;
1575
1464
  }
1576
1465
  }
1577
1466
  get listeners() {
@@ -1599,10 +1488,12 @@ class ReactiveSignal {
1599
1488
  };
1600
1489
  }
1601
1490
  if (!this._isListener) {
1602
- watchSignal(this, this._isSuspended);
1491
+ watchSignal(this);
1603
1492
  this.flags |= 16;
1604
1493
  }
1605
- schedulePull(this);
1494
+ if (this.watchCount > 0) {
1495
+ schedulePull(this);
1496
+ }
1606
1497
  current.set(listener, effective);
1607
1498
  }
1608
1499
  return () => {
@@ -1610,7 +1501,7 @@ class ReactiveSignal {
1610
1501
  current.delete(listener);
1611
1502
  if (current.size === 0) {
1612
1503
  cancelPull(this);
1613
- unwatchSignal(this, this._isSuspended);
1504
+ unwatchSignal(this);
1614
1505
  this.flags &= -17;
1615
1506
  this.listeners.updatedAt = 0;
1616
1507
  }
@@ -1620,39 +1511,15 @@ class ReactiveSignal {
1620
1511
  // This method is used in React hooks specifically. It returns a bound add method
1621
1512
  // that is cached to avoid creating a new one on each call, and it eagerly sets
1622
1513
  // the listener as watched so that relays that are accessed will be activated.
1623
- addListenerLazy() {
1514
+ addListenerLazy(watch = true) {
1624
1515
  if (!this._isListener) {
1625
- watchSignal(this, this._isSuspended);
1516
+ if (watch) {
1517
+ watchSignal(this);
1518
+ }
1626
1519
  this.flags |= 16;
1627
1520
  }
1628
1521
  return this.listeners.cachedBoundAdd;
1629
1522
  }
1630
- setSuspended(suspended) {
1631
- const { flags } = this;
1632
- const isListener = (flags & 16) !== 0;
1633
- const isSuspendedListener = (flags & 32) !== 0;
1634
- if (suspended && !isSuspendedListener) {
1635
- this.flags = flags | 32;
1636
- if (isListener) {
1637
- suspendSignal(this);
1638
- }
1639
- } else if (!suspended && isSuspendedListener) {
1640
- this.flags = flags & -33;
1641
- if (isListener) {
1642
- resumeSignal(this);
1643
- }
1644
- }
1645
- }
1646
- reset() {
1647
- this.flags = (this.def.isRelay ? 8 : 0) | 2;
1648
- this.dirtyHead = void 0;
1649
- this.updatedCount = 0;
1650
- this.computedCount = 0;
1651
- this.deps = /* @__PURE__ */ new Map();
1652
- this.subs = /* @__PURE__ */ new Map();
1653
- this.watchCount = 0;
1654
- this.suspendCount = 0;
1655
- }
1656
1523
  }
1657
1524
  const runListeners = (signal2) => {
1658
1525
  const { listeners } = signal2;
@@ -1670,6 +1537,10 @@ const isRelay = (signal2) => {
1670
1537
  function createReactiveSignal(def, args = [], key, scope) {
1671
1538
  return new ReactiveSignal(def, args, key, scope);
1672
1539
  }
1540
+ let requestScopeGetter;
1541
+ function setRequestScopeGetter(get) {
1542
+ requestScopeGetter = get;
1543
+ }
1673
1544
  let CONTEXT_ID = 0;
1674
1545
  class ContextImpl {
1675
1546
  defaultValue;
@@ -1711,7 +1582,6 @@ class SignalScope {
1711
1582
  contexts;
1712
1583
  children = /* @__PURE__ */ new Map();
1713
1584
  signals = /* @__PURE__ */ new Map();
1714
- gcCandidates = /* @__PURE__ */ new Set();
1715
1585
  setContexts(contexts) {
1716
1586
  for (const [context2, value] of contexts) {
1717
1587
  this.contexts[context2._key] = value;
@@ -1737,38 +1607,13 @@ class SignalScope {
1737
1607
  get(def, args) {
1738
1608
  const paramKey = def.paramKey?.(...args);
1739
1609
  const key = hashReactiveFn(def.compute, paramKey ? [paramKey] : args);
1740
- let signal2 = this.signals.get(key);
1610
+ let signal2 = this.signals.get(key)?.deref();
1741
1611
  if (signal2 === void 0) {
1742
1612
  signal2 = createReactiveSignal(def, args, key, this);
1743
- this.signals.set(key, signal2);
1613
+ this.signals.set(key, new WeakRef(signal2));
1744
1614
  }
1745
1615
  return signal2;
1746
1616
  }
1747
- markForGc(signal2) {
1748
- if (!this.gcCandidates.has(signal2)) {
1749
- this.gcCandidates.add(signal2);
1750
- scheduleGcSweep(this);
1751
- }
1752
- }
1753
- removeFromGc(signal2) {
1754
- this.gcCandidates.delete(signal2);
1755
- const { key } = signal2;
1756
- if (key) {
1757
- this.signals.set(key, signal2);
1758
- }
1759
- }
1760
- forceGc(signal2) {
1761
- this.signals.delete(signal2.key);
1762
- }
1763
- sweepGc() {
1764
- const signals = this.signals;
1765
- for (const signal2 of this.gcCandidates) {
1766
- if (signal2.watchCount === 0) {
1767
- signals.delete(signal2.key);
1768
- }
1769
- }
1770
- this.gcCandidates = /* @__PURE__ */ new Set();
1771
- }
1772
1617
  }
1773
1618
  let GLOBAL_SCOPE = new SignalScope([]);
1774
1619
  const getGlobalScope = () => {
@@ -1788,7 +1633,7 @@ const getInternalCurrentScope = () => {
1788
1633
  return CURRENT_SCOPE;
1789
1634
  };
1790
1635
  const getCurrentScope = (fallback = GLOBAL_SCOPE) => {
1791
- return CURRENT_SCOPE ?? getCurrentConsumer()?.scope ?? fallback;
1636
+ return CURRENT_SCOPE ?? getCurrentConsumer()?.scope ?? requestScopeGetter?.() ?? fallback;
1792
1637
  };
1793
1638
  const SCOPE_OWNER_MAP = /* @__PURE__ */ new WeakMap();
1794
1639
  const OWNER_CHILD_MAP = /* @__PURE__ */ new WeakMap();
@@ -1823,6 +1668,7 @@ exports.createReactiveDefinition = createReactiveDefinition;
1823
1668
  exports.createReactiveSignal = createReactiveSignal;
1824
1669
  exports.createRelay = createRelay;
1825
1670
  exports.createTask = createTask;
1671
+ exports.generatorResultToPromiseWithConsumer = generatorResultToPromiseWithConsumer;
1826
1672
  exports.getContext = getContext;
1827
1673
  exports.getCurrentConsumer = getCurrentConsumer;
1828
1674
  exports.getCurrentScope = getCurrentScope;
@@ -1832,18 +1678,21 @@ exports.getSignal = getSignal;
1832
1678
  exports.hashValue = hashValue;
1833
1679
  exports.isPromise = isPromise;
1834
1680
  exports.isReactivePromise = isReactivePromise;
1835
- exports.isRelay = isRelay$1;
1836
1681
  exports.isSignal = isSignal;
1682
+ exports.isThennable = isThennable;
1837
1683
  exports.notifier = notifier;
1838
1684
  exports.registerCustomHash = registerCustomHash;
1839
1685
  exports.runSignal = runSignal;
1686
+ exports.schedulePull = schedulePull;
1840
1687
  exports.scheduleTracer = scheduleTracer;
1688
+ exports.setCurrentConsumer = setCurrentConsumer;
1841
1689
  exports.setGlobalContexts = setGlobalContexts;
1842
1690
  exports.setReactivePromise = setReactivePromise;
1691
+ exports.setRequestScopeGetter = setRequestScopeGetter;
1843
1692
  exports.setScopeOwner = setScopeOwner;
1844
1693
  exports.settled = settled;
1845
1694
  exports.signal = signal;
1846
1695
  exports.unwatchSignal = unwatchSignal;
1847
1696
  exports.watchSignal = watchSignal;
1848
1697
  exports.withContexts = withContexts;
1849
- //# sourceMappingURL=contexts-DtQMtXO7.js.map
1698
+ //# sourceMappingURL=contexts-CM3QLfV8.js.map