@warp-drive-mirror/react 5.8.0-alpha.37 → 5.8.0-alpha.40

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 (37) hide show
  1. package/dist/unpkg/dev/index.js +75 -26
  2. package/dist/unpkg/dev/install.js +8 -10
  3. package/dist/unpkg/dev/reactive-context-CTtwoaBx.js +290 -0
  4. package/dist/unpkg/dev-deprecated/index.js +75 -26
  5. package/dist/unpkg/dev-deprecated/install.js +8 -10
  6. package/dist/unpkg/dev-deprecated/reactive-context-sqyJMb7I.js +290 -0
  7. package/dist/unpkg/prod/index.js +5 -30
  8. package/dist/unpkg/prod/install.js +3 -51
  9. package/dist/unpkg/prod/reactive-context-DKimDkR3.js +110 -0
  10. package/dist/unpkg/prod-deprecated/index.js +5 -30
  11. package/dist/unpkg/prod-deprecated/install.js +3 -51
  12. package/dist/unpkg/prod-deprecated/reactive-context-DKimDkR3.js +110 -0
  13. package/package.json +13 -21
  14. package/dist/unpkg/dev/declarations/-private/reactive-context.d.ts +0 -18
  15. package/dist/unpkg/dev/declarations/-private/request.d.ts +0 -141
  16. package/dist/unpkg/dev/declarations/-private/store-provider.d.ts +0 -19
  17. package/dist/unpkg/dev/declarations/index.d.ts +0 -7
  18. package/dist/unpkg/dev/declarations/install.d.ts +0 -3
  19. package/dist/unpkg/dev/reactive-context-ClTRYXie.js +0 -154
  20. package/dist/unpkg/dev-deprecated/declarations/-private/reactive-context.d.ts +0 -18
  21. package/dist/unpkg/dev-deprecated/declarations/-private/request.d.ts +0 -141
  22. package/dist/unpkg/dev-deprecated/declarations/-private/store-provider.d.ts +0 -19
  23. package/dist/unpkg/dev-deprecated/declarations/index.d.ts +0 -7
  24. package/dist/unpkg/dev-deprecated/declarations/install.d.ts +0 -3
  25. package/dist/unpkg/dev-deprecated/reactive-context-ClTRYXie.js +0 -154
  26. package/dist/unpkg/prod/declarations/-private/reactive-context.d.ts +0 -18
  27. package/dist/unpkg/prod/declarations/-private/request.d.ts +0 -141
  28. package/dist/unpkg/prod/declarations/-private/store-provider.d.ts +0 -19
  29. package/dist/unpkg/prod/declarations/index.d.ts +0 -7
  30. package/dist/unpkg/prod/declarations/install.d.ts +0 -3
  31. package/dist/unpkg/prod/reactive-context-ClTRYXie.js +0 -154
  32. package/dist/unpkg/prod-deprecated/declarations/-private/reactive-context.d.ts +0 -18
  33. package/dist/unpkg/prod-deprecated/declarations/-private/request.d.ts +0 -141
  34. package/dist/unpkg/prod-deprecated/declarations/-private/store-provider.d.ts +0 -19
  35. package/dist/unpkg/prod-deprecated/declarations/index.d.ts +0 -7
  36. package/dist/unpkg/prod-deprecated/declarations/install.d.ts +0 -3
  37. package/dist/unpkg/prod-deprecated/reactive-context-ClTRYXie.js +0 -154
@@ -1,11 +1,11 @@
1
- import { R as ReactiveContext } from "./reactive-context-ClTRYXie.js";
2
- export { W as WatcherContext } from "./reactive-context-ClTRYXie.js";
1
+ import { R as ReactiveContext } from "./reactive-context-CTtwoaBx.js";
2
+ export { W as WatcherContext } from "./reactive-context-CTtwoaBx.js";
3
3
  import '@warp-drive-mirror/core';
4
4
  import { useMemo, createContext, use, useRef, useEffect } from 'react';
5
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
- import { jsx, Fragment } from 'react/jsx-runtime';
5
+ import { jsxDEV, Fragment } from 'react/jsx-dev-runtime';
7
6
  import { DISPOSE, createRequestSubscription, signal } from '@warp-drive-mirror/core/store/-private';
8
7
  import '@warp-drive-mirror/core/request';
8
+ var _jsxFileName$1 = "/home/runner/work/warp-drive/warp-drive/warp-drive-packages/react/src/-private/store-provider.tsx";
9
9
  const StoreContext = /*#__PURE__*/createContext(null);
10
10
 
11
11
  /**
@@ -13,11 +13,11 @@ const StoreContext = /*#__PURE__*/createContext(null);
13
13
  */
14
14
  function useStore() {
15
15
  const store = use(StoreContext);
16
- macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
16
+ (test => {
17
17
  if (!test) {
18
18
  throw new Error("No Store provided via context. Please ensure you are using <StoreProvider> to provide a Store instance.");
19
19
  }
20
- })(store) : {};
20
+ })(store);
21
21
  return store;
22
22
  }
23
23
  /**
@@ -25,10 +25,14 @@ function useStore() {
25
25
  */
26
26
  function StoreProvider($props) {
27
27
  const store = useMemo(() => "store" in $props ? $props.store : new $props.Store(), ["store" in $props ? $props.store : $props.Store]);
28
- return /*#__PURE__*/jsx(StoreContext, {
28
+ return /*#__PURE__*/jsxDEV(StoreContext, {
29
29
  value: store,
30
30
  children: $props.children
31
- });
31
+ }, void 0, false, {
32
+ fileName: _jsxFileName$1,
33
+ lineNumber: 34,
34
+ columnNumber: 10
35
+ }, this);
32
36
  }
33
37
  const deferred = /* @__PURE__ */new WeakMap();
34
38
  function deferDecorator(proto, prop, desc) {
@@ -80,6 +84,7 @@ function initializeDeferredDecorator(target, prop) {
80
84
  });
81
85
  }
82
86
  }
87
+ var _jsxFileName = "/home/runner/work/warp-drive/warp-drive/warp-drive-packages/react/src/-private/request.tsx";
83
88
  const IdleBlockMissingError = new Error("No idle block provided for <Request> component, and no query or request was provided.");
84
89
  class ReactiveArgs {
85
90
  static {
@@ -106,9 +111,9 @@ class ReactiveArgs {
106
111
  const DefaultChrome = ({
107
112
  children
108
113
  }) => {
109
- return /*#__PURE__*/jsx(Fragment, {
114
+ return /*#__PURE__*/jsxDEV(Fragment, {
110
115
  children: children
111
- });
116
+ }, void 0, false);
112
117
  };
113
118
  function Throw({
114
119
  error
@@ -179,17 +184,25 @@ function Throw({
179
184
  * @category Components
180
185
  */
181
186
  function Request($props) {
182
- return /*#__PURE__*/jsx(ReactiveContext, {
183
- children: /*#__PURE__*/jsx(InternalRequest, {
187
+ return /*#__PURE__*/jsxDEV(ReactiveContext, {
188
+ children: /*#__PURE__*/jsxDEV(InternalRequest, {
184
189
  ...$props
185
- })
186
- });
190
+ }, void 0, false, {
191
+ fileName: _jsxFileName,
192
+ lineNumber: 172,
193
+ columnNumber: 7
194
+ }, this)
195
+ }, void 0, false, {
196
+ fileName: _jsxFileName,
197
+ lineNumber: 171,
198
+ columnNumber: 5
199
+ }, this);
187
200
  }
188
201
  function isStrictModeRender() {
189
202
  const count = useRef(0);
190
203
 
191
204
  // in debug we need to skip every second invocation
192
- if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
205
+ {
193
206
  if (count.current++ % 2 === 1) {
194
207
  return true;
195
208
  }
@@ -228,7 +241,7 @@ function InternalRequest($props) {
228
241
  return sink.current ? initialized.current.dispose : undefined;
229
242
  };
230
243
  let maybeEffect = effect;
231
- if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
244
+ {
232
245
  if (isStrict) {
233
246
  maybeEffect = () => {
234
247
  if (initialized.current) {
@@ -246,29 +259,65 @@ function InternalRequest($props) {
246
259
  useEffect(maybeEffect, [sink.current]);
247
260
  const state = $props.subscription ?? sink.current;
248
261
  const slots = $props.states;
249
- return /*#__PURE__*/jsx(Chrome, {
262
+ return /*#__PURE__*/jsxDEV(Chrome, {
250
263
  state: state.isIdle ? null : state.reqState,
251
264
  features: state.contentFeatures,
252
265
  children:
253
266
  // prettier-ignore
254
- state.isIdle && slots.idle ? /*#__PURE__*/jsx(slots.idle, {}) : state.isIdle ? /*#__PURE__*/jsx(Throw, {
267
+ state.isIdle && slots.idle ? /*#__PURE__*/jsxDEV(slots.idle, {}, void 0, false, {
268
+ fileName: _jsxFileName,
269
+ lineNumber: 256,
270
+ columnNumber: 38
271
+ }, this) : state.isIdle ? /*#__PURE__*/jsxDEV(Throw, {
255
272
  error: IdleBlockMissingError
256
- }) : state.reqState.isLoading ? slots.loading ? /*#__PURE__*/jsx(slots.loading, {
273
+ }, void 0, false, {
274
+ fileName: _jsxFileName,
275
+ lineNumber: 257,
276
+ columnNumber: 28
277
+ }, this) : state.reqState.isLoading ? slots.loading ? /*#__PURE__*/jsxDEV(slots.loading, {
257
278
  state: state.reqState.loadingState
258
- }) : '' : state.reqState.isCancelled && slots.cancelled ? /*#__PURE__*/jsx(slots.cancelled, {
279
+ }, void 0, false, {
280
+ fileName: _jsxFileName,
281
+ lineNumber: 258,
282
+ columnNumber: 56
283
+ }, this) : '' : state.reqState.isCancelled && slots.cancelled ? /*#__PURE__*/jsxDEV(slots.cancelled, {
259
284
  error: state.reqState.reason,
260
285
  features: state.errorFeatures
261
- }) : state.reqState.isError && slots.error ? /*#__PURE__*/jsx(slots.error, {
286
+ }, void 0, false, {
287
+ fileName: _jsxFileName,
288
+ lineNumber: 259,
289
+ columnNumber: 61
290
+ }, this) : state.reqState.isError && slots.error ? /*#__PURE__*/jsxDEV(slots.error, {
262
291
  error: state.reqState.reason,
263
292
  features: state.errorFeatures
264
- }) : state.reqState.isSuccess ? slots.content ? /*#__PURE__*/jsx(slots.content, {
293
+ }, void 0, false, {
294
+ fileName: _jsxFileName,
295
+ lineNumber: 260,
296
+ columnNumber: 53
297
+ }, this) : state.reqState.isSuccess ? slots.content ? /*#__PURE__*/jsxDEV(slots.content, {
265
298
  result: state.reqState.value,
266
299
  features: state.contentFeatures
267
- }) : /*#__PURE__*/jsx(Throw, {
300
+ }, void 0, false, {
301
+ fileName: _jsxFileName,
302
+ lineNumber: 261,
303
+ columnNumber: 56
304
+ }, this) : /*#__PURE__*/jsxDEV(Throw, {
268
305
  error: new Error('No content block provided for <Request> component.')
269
- }) : !state.reqState.isCancelled ? /*#__PURE__*/jsx(Throw, {
306
+ }, void 0, false, {
307
+ fileName: _jsxFileName,
308
+ lineNumber: 261,
309
+ columnNumber: 139
310
+ }, this) : !state.reqState.isCancelled ? /*#__PURE__*/jsxDEV(Throw, {
270
311
  error: state.reqState.reason
271
- }) : '' // never
272
- });
312
+ }, void 0, false, {
313
+ fileName: _jsxFileName,
314
+ lineNumber: 262,
315
+ columnNumber: 43
316
+ }, this) : '' // never
317
+ }, void 0, false, {
318
+ fileName: _jsxFileName,
319
+ lineNumber: 253,
320
+ columnNumber: 5
321
+ }, this);
273
322
  }
274
323
  export { ReactiveContext, Request, StoreProvider, Throw, useStore };
@@ -1,8 +1,7 @@
1
1
  import { use } from 'react';
2
2
  import { Signal } from 'signal-polyfill';
3
3
  import { setupSignals } from '@warp-drive-mirror/core/configure';
4
- import { W as WatcherContext } from "./reactive-context-ClTRYXie.js";
5
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
+ import { g as getGlobalConfig, W as WatcherContext } from "./reactive-context-CTtwoaBx.js";
6
5
 
7
6
  /**
8
7
  * {@include ./install.md}
@@ -20,7 +19,7 @@ function tryConsumeContext(signal) {
20
19
  // eslint-disable-next-line no-console
21
20
  console.error = logError;
22
21
  watcher?.watcher.watch(signal);
23
- if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
22
+ {
24
23
  if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
25
24
  // eslint-disable-next-line no-console
26
25
  console.log(`[WarpDrive] Consumed Context Signal`, signal, watcher);
@@ -31,7 +30,7 @@ function tryConsumeContext(signal) {
31
30
  console.error = logError;
32
31
  // if we are not in a React context, we will Error
33
32
  // so we just ignore it.
34
- if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
33
+ {
35
34
  if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
36
35
  // eslint-disable-next-line no-console
37
36
  console.log(`[WarpDrive] No Context Available To Consume Signal`, signal);
@@ -41,7 +40,7 @@ function tryConsumeContext(signal) {
41
40
  }
42
41
  let pending;
43
42
  async function settled() {
44
- if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
43
+ {
45
44
  // in testing mode we provide a test waiter integration
46
45
  if (!pending || !pending.length) return;
47
46
  const current = pending ?? [];
@@ -55,14 +54,14 @@ async function settled() {
55
54
  }
56
55
  function buildSignalConfig(options) {
57
56
  return {
58
- createSignal: (obj, key) => new Signal.State(macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? {
57
+ createSignal: (obj, key) => new Signal.State({
59
58
  obj,
60
59
  key
61
- } : null, {
60
+ }, {
62
61
  equals: () => false
63
62
  }),
64
63
  notifySignal: signal => {
65
- if (macroCondition(getGlobalConfig().WarpDriveMirror.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
64
+ {
66
65
  if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
67
66
  if (Signal.subtle.hasSinks(signal)) {
68
67
  // eslint-disable-next-line no-console
@@ -87,7 +86,7 @@ function buildSignalConfig(options) {
87
86
  };
88
87
  },
89
88
  waitFor: promise => {
90
- if (macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING)) {
89
+ {
91
90
  pending = pending || [];
92
91
  const newPromise = promise.finally(() => {
93
92
  pending = pending.filter(p => p !== newPromise);
@@ -95,7 +94,6 @@ function buildSignalConfig(options) {
95
94
  pending.push(newPromise);
96
95
  return newPromise;
97
96
  }
98
- return promise;
99
97
  },
100
98
  willSyncFlushWatchers: () => false
101
99
  };
@@ -0,0 +1,290 @@
1
+ import { Signal } from 'signal-polyfill';
2
+ import { createContext, useMemo, useSyncExternalStore } from 'react';
3
+ import { jsxDEV } from 'react/jsx-dev-runtime';
4
+
5
+ /*
6
+ These are the runtime implementations for the javascript macros that have
7
+ runtime implementations.
8
+
9
+ Not every macro has a runtime implementation, some only make sense in the
10
+ build and always run there.
11
+
12
+ Even when we have runtime implementations, we are still careful to emit static
13
+ errors during the build wherever possible, and runtime errors when necessary,
14
+ so that you're not surprised when you switch from runtime-mode to compile-time
15
+ mode.
16
+ */
17
+
18
+ // This is here as a compile target for `getConfig` and `getOwnConfig` when
19
+ // we're in runtime mode. This is not public API to call from your own code.
20
+ function config(packageRoot) {
21
+ return runtimeConfig.packages[packageRoot];
22
+ }
23
+ function getGlobalConfig() {
24
+ return runtimeConfig.global;
25
+ }
26
+ const runtimeConfig = initializeRuntimeMacrosConfig();
27
+
28
+ // this exists to be targeted by our babel plugin
29
+ function initializeRuntimeMacrosConfig() {
30
+ return {
31
+ "packages": {},
32
+ "global": {
33
+ "@embroider/macros": {
34
+ "isTesting": false
35
+ },
36
+ "WarpDrive": {
37
+ "debug": {
38
+ "DEBUG_RELATIONSHIP_NOTIFICATIONS": false,
39
+ "LOG_CACHE": false,
40
+ "LOG_CACHE_POLICY": false,
41
+ "LOG_GRAPH": false,
42
+ "LOG_IDENTIFIERS": false,
43
+ "LOG_INSTANCE_CACHE": false,
44
+ "LOG_METRIC_COUNTS": false,
45
+ "LOG_MUTATIONS": false,
46
+ "LOG_NOTIFICATIONS": false,
47
+ "LOG_OPERATIONS": false,
48
+ "LOG_PAYLOADS": false,
49
+ "LOG_REACT_SIGNAL_INTEGRATION": false,
50
+ "LOG_REQUESTS": false,
51
+ "LOG_REQUEST_STATUS": false,
52
+ "__INTERNAL_LOG_NATIVE_MAP_SET_COUNTS": false
53
+ },
54
+ "polyfillUUID": false,
55
+ "includeDataAdapter": true,
56
+ "compatWith": "99.0",
57
+ "deprecations": {
58
+ "DEPRECATE_CATCH_ALL": false,
59
+ "DEPRECATE_COMPUTED_CHAINS": false,
60
+ "DEPRECATE_EMBER_INFLECTOR": false,
61
+ "DEPRECATE_LEGACY_IMPORTS": false,
62
+ "DEPRECATE_MANY_ARRAY_DUPLICATES": false,
63
+ "DEPRECATE_NON_STRICT_ID": false,
64
+ "DEPRECATE_NON_STRICT_TYPES": false,
65
+ "DEPRECATE_NON_UNIQUE_PAYLOADS": false,
66
+ "DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE": false,
67
+ "DEPRECATE_STORE_EXTENDS_EMBER_OBJECT": false,
68
+ "DEPRECATE_TRACKING_PACKAGE": false,
69
+ "DISABLE_7X_DEPRECATIONS": false,
70
+ "ENABLE_LEGACY_REQUEST_METHODS": false,
71
+ "ENABLE_LEGACY_SCHEMA_SERVICE": false
72
+ },
73
+ "features": {
74
+ "ENFORCE_STRICT_RESOURCE_FINALIZATION": false,
75
+ "JSON_API_CACHE_VALIDATION_ERRORS": false,
76
+ "SAMPLE_FEATURE_FLAG": null
77
+ },
78
+ "activeLogging": {
79
+ "DEBUG_RELATIONSHIP_NOTIFICATIONS": true,
80
+ "LOG_CACHE": true,
81
+ "LOG_CACHE_POLICY": true,
82
+ "LOG_GRAPH": true,
83
+ "LOG_IDENTIFIERS": true,
84
+ "LOG_INSTANCE_CACHE": true,
85
+ "LOG_METRIC_COUNTS": true,
86
+ "LOG_MUTATIONS": true,
87
+ "LOG_NOTIFICATIONS": true,
88
+ "LOG_OPERATIONS": true,
89
+ "LOG_PAYLOADS": true,
90
+ "LOG_REACT_SIGNAL_INTEGRATION": true,
91
+ "LOG_REQUESTS": true,
92
+ "LOG_REQUEST_STATUS": true,
93
+ "__INTERNAL_LOG_NATIVE_MAP_SET_COUNTS": true
94
+ },
95
+ "env": {
96
+ "TESTING": true,
97
+ "PRODUCTION": false,
98
+ "DEBUG": true,
99
+ "IS_RECORDING": false,
100
+ "IS_CI": true,
101
+ "SHOULD_RECORD": false
102
+ }
103
+ }
104
+ }
105
+ };
106
+ }
107
+ function updaterMethods() {
108
+ return {
109
+ config,
110
+ getGlobalConfig,
111
+ setConfig(packageRoot, value) {
112
+ runtimeConfig.packages[packageRoot] = value;
113
+ },
114
+ setGlobalConfig(key, value) {
115
+ runtimeConfig.global[key] = value;
116
+ }
117
+ };
118
+ }
119
+
120
+ // this is how runtime config can get injected at boot. I'm not sure yet if this
121
+ // should be public API, but we certainly need it internally to set things like
122
+ // the global fastboot.isRunning.
123
+ //
124
+ // consumers of this API push a function onto
125
+ // window._embroider_macros_runtime_config. The function is given four methods
126
+ // which allow it to read and write the per-package and global configs. The
127
+ // reason for allowing both read & write is that merging strategies are up to
128
+ // each consumers -- read first, then merge, then write.
129
+ //
130
+ // For an example user of this API, see where we generate
131
+ // embroider_macros_fastboot_init.js' in @embroider/core.
132
+ let updaters = typeof window !== 'undefined' ? window._embroider_macros_runtime_config : undefined;
133
+ if (updaters) {
134
+ let methods = updaterMethods();
135
+ for (let updater of updaters) {
136
+ updater(methods);
137
+ }
138
+ }
139
+ var _jsxFileName = "/home/runner/work/warp-drive/warp-drive/warp-drive-packages/react/src/-private/reactive-context.tsx";
140
+ let nextFlush = null;
141
+ let watchers = [];
142
+ let watcherId = 0;
143
+ function clearWatcher(state) {
144
+ state.watcher.unwatch(...Signal.subtle.introspectSources(state.watcher));
145
+ }
146
+ function flush(state) {
147
+ state.pending = false;
148
+ if (state.destroyed) {
149
+ {
150
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
151
+ console.log(`[WarpDrive] Detected Watcher Destroyed During Notify Flush, clearing signals`);
152
+ }
153
+ }
154
+ state.snapshot = null;
155
+ clearWatcher(state);
156
+ return;
157
+ }
158
+ {
159
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
160
+ console.log(`[WarpDrive] Notifying React That WatcherContext:${state.watcherId} Has Updated`);
161
+ console.log("all signals", new Set(Signal.subtle.introspectSources(state.watcher)));
162
+ console.log("dirty signals", new Set(state.watcher.getPending()));
163
+ }
164
+ } // any time signals have changed, we notify React that our store has updated
165
+ state.snapshot = {
166
+ watcher: state.watcher
167
+ };
168
+ if (state.notifyReact) state.notifyReact();
169
+
170
+ // tell the Watcher to start watching for changes again
171
+ // by signaling that notifications have been flushed.
172
+ state.watcher.watch();
173
+ }
174
+ function _createWatcher() {
175
+ const id = watcherId++;
176
+ {
177
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
178
+ console.log(`[WarpDrive] Creating a WatcherContext:${id}`);
179
+ }
180
+ }
181
+ const state = {
182
+ watcherId: id,
183
+ pending: false,
184
+ destroyed: false,
185
+ notifyReact: null,
186
+ watcher: null,
187
+ // the extra wrapper returned here ensures that the context value for the watcher
188
+ // changes causing a re-render when the watcher is updated.
189
+ snapshot: null
190
+ };
191
+ state.watcher = new Signal.subtle.Watcher((...args) => {
192
+ {
193
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
194
+ console.log(`watcher ${state.watcherId} notified`, args, state.watcher);
195
+ }
196
+ }
197
+ if (!state.pending && !state.destroyed) {
198
+ watchers.push(state);
199
+ state.pending = true;
200
+ if (!nextFlush) {
201
+ nextFlush = new Promise(resolve => {
202
+ queueMicrotask(() => {
203
+ queueMicrotask(() => {
204
+ queueMicrotask(() => {
205
+ watchers.forEach(flush);
206
+ {
207
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
208
+ console.log("Flushed watcher:", watchers.map(w => w.watcherId));
209
+ }
210
+ }
211
+ watchers = [];
212
+ nextFlush = null;
213
+ resolve();
214
+ });
215
+ });
216
+ });
217
+ });
218
+ }
219
+ } else if (state.destroyed) {
220
+ {
221
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
222
+ console.log(`[WarpDrive] Detected Watcher Destroyed During Notify, clearing signals`);
223
+ }
224
+ } // if we are destroyed, we clear the watcher signals
225
+ // so that it does not continue to watch for changes.
226
+ state.snapshot = null;
227
+ clearWatcher(state);
228
+ }
229
+ });
230
+
231
+ // The watcher won't begin watching until we call `watcher.watch()`
232
+ state.watcher.watch();
233
+ state.snapshot = {
234
+ watcher: state.watcher
235
+ };
236
+ return state;
237
+ }
238
+ function useWatcher() {
239
+ const state = useMemo(_createWatcher, []);
240
+ return useSyncExternalStore(notifyChanged => {
241
+ {
242
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
243
+ console.log(`[WarpDrive] Subscribing to Watcher`);
244
+ }
245
+ }
246
+ state.destroyed = false;
247
+ state.notifyReact = notifyChanged;
248
+
249
+ // The watcher won't begin watching until we call `watcher.watch()`
250
+ state.watcher.watch();
251
+ return () => {
252
+ {
253
+ if (getGlobalConfig().WarpDriveMirror.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
254
+ console.log(`[WarpDrive] Deactivating Watcher Subscription`);
255
+ }
256
+ }
257
+ state.destroyed = true;
258
+ state.notifyReact = null;
259
+ };
260
+ }, () => state.snapshot);
261
+ }
262
+
263
+ /**
264
+ * @category Contexts
265
+ */
266
+ const WatcherContext = /*#__PURE__*/createContext(null);
267
+
268
+ /**
269
+ *
270
+ * @category Components
271
+ */
272
+ function ReactiveContext({
273
+ children
274
+ }) {
275
+ const watcher = useWatcher();
276
+ /**
277
+ * Unlike other frameworks, React does not have a built-in way to provide
278
+ * a context value other than by rendering an extra component.
279
+ *
280
+ */
281
+ return /*#__PURE__*/jsxDEV(WatcherContext, {
282
+ value: watcher,
283
+ children: children
284
+ }, void 0, false, {
285
+ fileName: _jsxFileName,
286
+ lineNumber: 159,
287
+ columnNumber: 10
288
+ }, this);
289
+ }
290
+ export { ReactiveContext as R, WatcherContext as W, getGlobalConfig as g };