@warp-drive/react 5.9.0-alpha.20 → 5.9.0-alpha.22

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 (45) hide show
  1. package/dist/index.d.ts +180 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +215 -256
  4. package/dist/index.js.map +1 -0
  5. package/dist/install.d.ts +21 -0
  6. package/dist/install.d.ts.map +1 -0
  7. package/dist/install.js +88 -107
  8. package/dist/install.js.map +1 -0
  9. package/dist/reactive-context-DNq02nr1.js +122 -0
  10. package/dist/reactive-context-DNq02nr1.js.map +1 -0
  11. package/dist/unpkg/dev/index.js +259 -304
  12. package/dist/unpkg/dev/index.js.map +1 -0
  13. package/dist/unpkg/dev/install.js +80 -105
  14. package/dist/unpkg/dev/install.js.map +1 -0
  15. package/dist/unpkg/dev/reactive-context-ir4_7OCl.js +218 -0
  16. package/dist/unpkg/dev/reactive-context-ir4_7OCl.js.map +1 -0
  17. package/dist/unpkg/dev-deprecated/index.js +259 -304
  18. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  19. package/dist/unpkg/dev-deprecated/install.js +80 -105
  20. package/dist/unpkg/dev-deprecated/install.js.map +1 -0
  21. package/dist/unpkg/dev-deprecated/reactive-context-CBrZV0cR.js +218 -0
  22. package/dist/unpkg/dev-deprecated/reactive-context-CBrZV0cR.js.map +1 -0
  23. package/dist/unpkg/prod/index.js +198 -231
  24. package/dist/unpkg/prod/index.js.map +1 -0
  25. package/dist/unpkg/prod/install.js +54 -61
  26. package/dist/unpkg/prod/install.js.map +1 -0
  27. package/dist/unpkg/prod/reactive-context-CvfXAZqb.js +92 -0
  28. package/dist/unpkg/prod/reactive-context-CvfXAZqb.js.map +1 -0
  29. package/dist/unpkg/prod-deprecated/index.js +198 -231
  30. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  31. package/dist/unpkg/prod-deprecated/install.js +54 -61
  32. package/dist/unpkg/prod-deprecated/install.js.map +1 -0
  33. package/dist/unpkg/prod-deprecated/reactive-context-CvfXAZqb.js +92 -0
  34. package/dist/unpkg/prod-deprecated/reactive-context-CvfXAZqb.js.map +1 -0
  35. package/package.json +15 -17
  36. package/declarations/-private/reactive-context.d.ts +0 -21
  37. package/declarations/-private/request.d.ts +0 -148
  38. package/declarations/-private/store-provider.d.ts +0 -19
  39. package/declarations/index.d.ts +0 -7
  40. package/declarations/install.d.ts +0 -17
  41. package/dist/reactive-context-ClTRYXie.js +0 -154
  42. package/dist/unpkg/dev/reactive-context-4Y50NyRg.js +0 -306
  43. package/dist/unpkg/dev-deprecated/reactive-context-D54NwOLZ.js +0 -306
  44. package/dist/unpkg/prod/reactive-context-DKimDkR3.js +0 -110
  45. package/dist/unpkg/prod-deprecated/reactive-context-DKimDkR3.js +0 -110
package/dist/install.js CHANGED
@@ -1,119 +1,100 @@
1
- import { use } from 'react';
2
- import { Signal } from 'signal-polyfill';
3
- import { setupSignals } from '@warp-drive/core/configure';
4
- import { W as WatcherContext } from "./reactive-context-ClTRYXie.js";
5
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
1
+ import { n as WatcherContext } from "./reactive-context-DNq02nr1.js";
2
+ import { Signal } from "signal-polyfill";
3
+ import { use } from "react";
4
+ import { getGlobalConfig, macroCondition } from "@embroider/macros";
5
+ import { setupSignals } from "@warp-drive/core/configure";
6
6
 
7
+ //#region src/install.ts
7
8
  /**
8
- * {@include ./install.md}
9
- * @module
10
- */
11
-
9
+ * {@include ./install.md}
10
+ * @module
11
+ */
12
12
  function tryConsumeContext(signal) {
13
- // eslint-disable-next-line no-console
14
- const logError = console.error;
15
- try {
16
- // eslint-disable-next-line no-console
17
- console.error = () => {};
18
- // ensure signals are watched by our closest watcher
19
- const watcher = use(WatcherContext);
20
- // eslint-disable-next-line no-console
21
- console.error = logError;
22
- watcher?.watcher.watch(signal);
23
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
24
- if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
25
- // eslint-disable-next-line no-console
26
- console.log(`[WarpDrive] Consumed Context Signal`, signal, watcher);
27
- }
28
- }
29
- } catch {
30
- // eslint-disable-next-line no-console
31
- console.error = logError;
32
- // if we are not in a React context, we will Error
33
- // so we just ignore it.
34
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
35
- if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
36
- // eslint-disable-next-line no-console
37
- console.log(`[WarpDrive] No Context Available To Consume Signal`, signal);
38
- }
39
- }
40
- }
13
+ const logError = console.error;
14
+ try {
15
+ console.error = () => {};
16
+ const watcher = use(WatcherContext);
17
+ console.error = logError;
18
+ watcher?.watcher.watch(signal);
19
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
20
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) console.log(`[WarpDrive] Consumed Context Signal`, signal, watcher);
21
+ }
22
+ } catch {
23
+ console.error = logError;
24
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
25
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) console.log(`[WarpDrive] No Context Available To Consume Signal`, signal);
26
+ }
27
+ }
41
28
  }
42
29
  let pending;
43
30
  /**
44
- * Resolves once all pending requests started via WarpDrive's React signal
45
- * integration have settled. Only tracks requests while `TESTING` is enabled;
46
- * a no-op otherwise.
47
- *
48
- * @public
49
- */
31
+ * Resolves once all pending requests started via WarpDrive's React signal
32
+ * integration have settled. Only tracks requests while `TESTING` is enabled;
33
+ * a no-op otherwise.
34
+ *
35
+ * @public
36
+ */
50
37
  async function settled() {
51
- if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
52
- // in testing mode we provide a test waiter integration
53
- if (!pending || !pending.length) return;
54
- const current = pending ?? [];
55
- pending = [];
56
- await Promise.allSettled(current);
57
- await Promise.resolve();
58
- await Promise.resolve();
59
- await Promise.resolve();
60
- return settled();
61
- }
38
+ if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
39
+ if (!pending || !pending.length) return;
40
+ const current = pending ?? [];
41
+ pending = [];
42
+ await Promise.allSettled(current);
43
+ await Promise.resolve();
44
+ await Promise.resolve();
45
+ await Promise.resolve();
46
+ return settled();
47
+ }
62
48
  }
63
-
64
49
  /**
65
- * Builds the {@link SignalHooks} implementation backed by the
66
- * [Signal Polyfill](https://github.com/proposal-signals/signal-polyfill),
67
- * used to wire WarpDrive's reactivity primitives into React.
68
- *
69
- * @public
70
- */
50
+ * Builds the {@link SignalHooks} implementation backed by the
51
+ * [Signal Polyfill](https://github.com/proposal-signals/signal-polyfill),
52
+ * used to wire WarpDrive's reactivity primitives into React.
53
+ *
54
+ * @public
55
+ */
71
56
  function buildSignalConfig(options) {
72
- return {
73
- createSignal: (obj, key) => new Signal.State(macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? {
74
- obj,
75
- key
76
- } : null, {
77
- equals: () => false
78
- }),
79
- notifySignal: signal => {
80
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
81
- if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
82
- if (Signal.subtle.hasSinks(signal)) {
83
- // eslint-disable-next-line no-console
84
- console.log(`[WarpDrive] Notifying Signal`, signal);
85
- } else {
86
- // eslint-disable-next-line no-console
87
- console.log(`[WarpDrive] Notified Signal That Has No Watcher`, signal);
88
- }
89
- }
90
- }
91
- signal.set(signal.get());
92
- },
93
- consumeSignal: signal => {
94
- tryConsumeContext(signal);
95
- void signal.get();
96
- },
97
- createMemo: (object, key, fn) => {
98
- const memo = new Signal.Computed(fn);
99
- return () => {
100
- tryConsumeContext(memo);
101
- return memo.get();
102
- };
103
- },
104
- waitFor: promise => {
105
- if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
106
- pending = pending || [];
107
- const newPromise = promise.finally(() => {
108
- pending = pending.filter(p => p !== newPromise);
109
- });
110
- pending.push(newPromise);
111
- return newPromise;
112
- }
113
- return promise;
114
- },
115
- willSyncFlushWatchers: () => false
116
- };
57
+ return {
58
+ createSignal: (obj, key) => new Signal.State(macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? {
59
+ obj,
60
+ key
61
+ } : null, { equals: () => false }),
62
+ notifySignal: (signal) => {
63
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
64
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
65
+ if (Signal.subtle.hasSinks(signal)) console.log(`[WarpDrive] Notifying Signal`, signal);
66
+ else console.log(`[WarpDrive] Notified Signal That Has No Watcher`, signal);
67
+ }
68
+ }
69
+ signal.set(signal.get());
70
+ },
71
+ consumeSignal: (signal) => {
72
+ tryConsumeContext(signal);
73
+ signal.get();
74
+ },
75
+ createMemo: (object, key, fn) => {
76
+ const memo = new Signal.Computed(fn);
77
+ return () => {
78
+ tryConsumeContext(memo);
79
+ return memo.get();
80
+ };
81
+ },
82
+ waitFor: (promise) => {
83
+ if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
84
+ pending = pending || [];
85
+ const newPromise = promise.finally(() => {
86
+ pending = pending.filter((p) => p !== newPromise);
87
+ });
88
+ pending.push(newPromise);
89
+ return newPromise;
90
+ }
91
+ return promise;
92
+ },
93
+ willSyncFlushWatchers: () => false
94
+ };
117
95
  }
118
96
  setupSignals(buildSignalConfig);
119
- export { buildSignalConfig, settled };
97
+
98
+ //#endregion
99
+ export { buildSignalConfig, settled };
100
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","names":["use","Signal","setupSignals","WatcherContext","getGlobalConfig","macroCondition","tryConsumeContext","signal","logError","console","error","watcher","watch","WarpDrive","activeLogging","LOG_REACT_SIGNAL_INTEGRATION","debug","globalThis","getWarpDriveRuntimeConfig","log","pending","settled","env","TESTING","length","current","Promise","allSettled","resolve","buildSignalConfig","options","createSignal","obj","key","State","DEBUG","equals","notifySignal","subtle","hasSinks","set","get","consumeSignal","createMemo","object","fn","memo","Computed","waitFor","promise","newPromise","finally","filter","p","push","willSyncFlushWatchers"],"sources":["../src/install.ts"],"sourcesContent":["/**\n * {@include ./install.md}\n * @module\n */\n\nimport { use } from 'react';\nimport { Signal } from 'signal-polyfill';\n\nimport { LOG_REACT_SIGNAL_INTEGRATION } from '@warp-drive/core/build-config/debugging';\nimport { DEBUG, TESTING } from '@warp-drive/core/build-config/env';\nimport { type HooksOptions, setupSignals, type SignalHooks } from '@warp-drive/core/configure';\n\nimport { WatcherContext } from './-private/reactive-context';\n\nfunction tryConsumeContext(signal: Signal.State<unknown> | Signal.Computed<unknown>): void {\n // eslint-disable-next-line no-console\n const logError = console.error;\n try {\n // eslint-disable-next-line no-console\n console.error = () => {};\n // ensure signals are watched by our closest watcher\n const watcher = use(WatcherContext);\n // eslint-disable-next-line no-console\n console.error = logError;\n watcher?.watcher.watch(signal);\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n // eslint-disable-next-line no-console\n console.log(`[WarpDrive] Consumed Context Signal`, signal, watcher);\n }\n } catch {\n // eslint-disable-next-line no-console\n console.error = logError;\n // if we are not in a React context, we will Error\n // so we just ignore it.\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n // eslint-disable-next-line no-console\n console.log(`[WarpDrive] No Context Available To Consume Signal`, signal);\n }\n }\n}\n\nlet pending: Promise<unknown>[];\n/**\n * Resolves once all pending requests started via WarpDrive's React signal\n * integration have settled. Only tracks requests while `TESTING` is enabled;\n * a no-op otherwise.\n *\n * @public\n */\nexport async function settled(): Promise<void> {\n if (TESTING) {\n // in testing mode we provide a test waiter integration\n if (!pending || !pending.length) return;\n const current = pending ?? [];\n pending = [];\n await Promise.allSettled(current);\n await Promise.resolve();\n await Promise.resolve();\n await Promise.resolve();\n\n return settled();\n }\n}\n\n/**\n * Builds the {@link SignalHooks} implementation backed by the\n * [Signal Polyfill](https://github.com/proposal-signals/signal-polyfill),\n * used to wire WarpDrive's reactivity primitives into React.\n *\n * @public\n */\nexport function buildSignalConfig(options: HooksOptions): SignalHooks {\n return {\n createSignal: (obj: object, key: string | symbol) =>\n new Signal.State(DEBUG ? { obj, key } : null, { equals: () => false }),\n\n notifySignal: (signal: Signal.State<unknown>) => {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n if (Signal.subtle.hasSinks(signal)) {\n // eslint-disable-next-line no-console\n console.log(`[WarpDrive] Notifying Signal`, signal);\n } else {\n // eslint-disable-next-line no-console\n console.log(`[WarpDrive] Notified Signal That Has No Watcher`, signal);\n }\n }\n signal.set(signal.get());\n },\n\n consumeSignal: (signal: Signal.State<unknown>) => {\n tryConsumeContext(signal);\n void signal.get();\n },\n\n createMemo: <F>(object: object, key: string | symbol, fn: () => F): (() => F) => {\n const memo = new Signal.Computed<F>(fn);\n return () => {\n tryConsumeContext(memo);\n\n return memo.get();\n };\n },\n\n waitFor: (promise) => {\n if (TESTING) {\n pending = pending || [];\n const newPromise = promise.finally(() => {\n pending = pending.filter((p) => p !== newPromise);\n });\n pending.push(newPromise);\n return newPromise;\n }\n return promise;\n },\n\n willSyncFlush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AAEH;GAAKC;EAAI,IAAI,MAAM,EAAEG,cAAc,MAAM,CAAC;EAEvEC,eAAe9B,WAAkC;GAC/C,IAAAF,eAAAD,gBAAA,CAAA,CAAAS,UAAAC,cAAAC,4BAAA,GAAA;QAAAX,gBAAA,CAAA,CAAAS,UAAAG,MAAAD,gCAAAE,WAAAC,0BAAA,CAAA,CAAAF,MAAAD,8BAAkC;KAChC,IAAId,OAAOqC,OAAOC,SAAShC,MAAM,GAE/BE,QAAQU,IAAI,gCAAgCZ,MAAM;UAGlDE,QAAQU,IAAI,mDAAmDZ,MAAM;IAEzE;;GACAA,OAAOiC,IAAIjC,OAAOkC,IAAI,CAAC;EACzB;EAEAC,gBAAgBnC,WAAkC;GAChDD,kBAAkBC,MAAM;GACxB,AAAKA,OAAOkC,IAAI;EAClB;EAEAE,aAAgBC,QAAgBX,KAAsBY,OAA2B;GAC/E,MAAMC,OAAO,IAAI7C,OAAO8C,SAAYF,EAAE;GACtC,aAAa;IACXvC,kBAAkBwC,IAAI;IAEtB,OAAOA,KAAKL,IAAI;GAClB;EACF;EAEAO,UAAUC,YAAY;GACpB,IAAA5C,eAAAD,gBAAA,CAAA,CAAAS,UAAAS,IAAAC,OAAA,GAAa;IACXH,UAAUA,WAAW,CAAA;IACrB,MAAM8B,aAAaD,QAAQE,cAAc;KACvC/B,UAAUA,QAAQgC,QAAQC,MAAMA,MAAMH,UAAU;IAClD,CAAC;IACD9B,QAAQkC,KAAKJ,UAAU;IACvB,OAAOA;GACT;GACA,OAAOD;EACT;EAEAM,6BAA6B;CAC/B;AACF;AAEArD,aAAa2B,iBAAiB"}
@@ -0,0 +1,122 @@
1
+ import { Signal } from "signal-polyfill";
2
+ import { createContext, useMemo, useSyncExternalStore } from "react";
3
+ import { getGlobalConfig, macroCondition } from "@embroider/macros";
4
+ import { jsx } from "react/jsx-runtime";
5
+
6
+ //#region src/-private/reactive-context.tsx
7
+ let nextFlush = null;
8
+ let watchers = [];
9
+ let watcherId = 0;
10
+ function clearWatcher(state) {
11
+ state.watcher.unwatch(...Signal.subtle.introspectSources(state.watcher));
12
+ }
13
+ function flush(state) {
14
+ state.pending = false;
15
+ if (state.destroyed) {
16
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
17
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) console.log(`[WarpDrive] Detected Watcher Destroyed During Notify Flush, clearing signals`);
18
+ }
19
+ state.snapshot = null;
20
+ clearWatcher(state);
21
+ return;
22
+ }
23
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
24
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
25
+ console.log(`[WarpDrive] Notifying React That WatcherContext:${state.watcherId} Has Updated`);
26
+ console.log("all signals", new Set(Signal.subtle.introspectSources(state.watcher)));
27
+ console.log("dirty signals", new Set(state.watcher.getPending()));
28
+ }
29
+ }
30
+ state.snapshot = { watcher: state.watcher };
31
+ if (state.notifyReact) state.notifyReact();
32
+ state.watcher.watch();
33
+ }
34
+ function _createWatcher() {
35
+ const id = watcherId++;
36
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
37
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) console.log(`[WarpDrive] Creating a WatcherContext:${id}`);
38
+ }
39
+ const state = {
40
+ watcherId: id,
41
+ pending: false,
42
+ destroyed: false,
43
+ notifyReact: null,
44
+ watcher: null,
45
+ snapshot: null
46
+ };
47
+ state.watcher = new Signal.subtle.Watcher((...args) => {
48
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
49
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) console.log(`watcher ${state.watcherId} notified`, args, state.watcher);
50
+ }
51
+ if (!state.pending && !state.destroyed) {
52
+ watchers.push(state);
53
+ state.pending = true;
54
+ if (!nextFlush) nextFlush = new Promise((resolve) => {
55
+ queueMicrotask(() => {
56
+ queueMicrotask(() => {
57
+ queueMicrotask(() => {
58
+ watchers.forEach(flush);
59
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
60
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) console.log("Flushed watcher:", watchers.map((w) => w.watcherId));
61
+ }
62
+ watchers = [];
63
+ nextFlush = null;
64
+ resolve();
65
+ });
66
+ });
67
+ });
68
+ });
69
+ } else if (state.destroyed) {
70
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
71
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) console.log(`[WarpDrive] Detected Watcher Destroyed During Notify, clearing signals`);
72
+ }
73
+ state.snapshot = null;
74
+ clearWatcher(state);
75
+ }
76
+ });
77
+ state.watcher.watch();
78
+ state.snapshot = { watcher: state.watcher };
79
+ return state;
80
+ }
81
+ function useWatcher() {
82
+ const state = useMemo(_createWatcher, []);
83
+ return useSyncExternalStore((notifyChanged) => {
84
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
85
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) console.log(`[WarpDrive] Subscribing to Watcher`);
86
+ }
87
+ state.destroyed = false;
88
+ state.notifyReact = notifyChanged;
89
+ state.watcher.watch();
90
+ return () => {
91
+ if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
92
+ if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) console.log(`[WarpDrive] Deactivating Watcher Subscription`);
93
+ }
94
+ state.destroyed = true;
95
+ state.notifyReact = null;
96
+ };
97
+ }, () => state.snapshot);
98
+ }
99
+ /**
100
+ * @category Contexts
101
+ */
102
+ const WatcherContext = /*#__PURE__*/ createContext(null);
103
+ /**
104
+ *
105
+ * @category Components
106
+ */
107
+ function ReactiveContext({ children }) {
108
+ const watcher = useWatcher();
109
+ /**
110
+ * Unlike other frameworks, React does not have a built-in way to provide
111
+ * a context value other than by rendering an extra component.
112
+ *
113
+ */
114
+ return /*#__PURE__*/ jsx(WatcherContext, {
115
+ value: watcher,
116
+ children
117
+ });
118
+ }
119
+
120
+ //#endregion
121
+ export { WatcherContext as n, ReactiveContext as t };
122
+ //# sourceMappingURL=reactive-context-DNq02nr1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive-context-DNq02nr1.js","names":["Signal","createContext","useSyncExternalStore","useMemo","getGlobalConfig","macroCondition","jsx","_jsx","nextFlush","watchers","watcherId","clearWatcher","state","watcher","unwatch","subtle","introspectSources","flush","pending","destroyed","WarpDrive","activeLogging","LOG_REACT_SIGNAL_INTEGRATION","debug","globalThis","getWarpDriveRuntimeConfig","console","log","snapshot","Set","getPending","notifyReact","watch","_createWatcher","id","Watcher","args","push","Promise","resolve","queueMicrotask","forEach","map","w","useWatcher","notifyChanged","WatcherContext","ReactiveContext","children","value"],"sources":["../src/-private/reactive-context.tsx"],"sourcesContent":["import { Signal } from \"signal-polyfill\";\nimport { createContext, type JSX, type ReactNode, useSyncExternalStore, type Context, useMemo } from \"react\";\nimport { LOG_REACT_SIGNAL_INTEGRATION } from \"@warp-drive/core/build-config/debugging\";\n\nlet nextFlush: Promise<void> | null = null;\nlet watchers: WatcherState[] = [];\nlet watcherId = 0;\n\ninterface WatcherState {\n watcherId: number;\n pending: boolean;\n destroyed: boolean;\n notifyReact: (() => void) | null;\n watcher: Signal.subtle.Watcher;\n\n // the extra wrapper returned here ensures that the context value for the watcher\n // changes causing a re-render when the watcher is updated.\n snapshot: { watcher: Signal.subtle.Watcher } | null;\n}\n\nfunction clearWatcher(state: WatcherState) {\n state.watcher.unwatch(...Signal.subtle.introspectSources(state.watcher));\n}\n\nfunction flush(state: WatcherState) {\n state.pending = false;\n if (state.destroyed) {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n console.log(`[WarpDrive] Detected Watcher Destroyed During Notify Flush, clearing signals`);\n }\n state.snapshot = null;\n clearWatcher(state);\n return;\n }\n\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n console.log(`[WarpDrive] Notifying React That WatcherContext:${state.watcherId} Has Updated`);\n console.log(\"all signals\", new Set(Signal.subtle.introspectSources(state.watcher)));\n console.log(\"dirty signals\", new Set(state.watcher.getPending()));\n }\n\n // any time signals have changed, we notify React that our store has updated\n state.snapshot = { watcher: state.watcher };\n if (state.notifyReact) state.notifyReact();\n\n // tell the Watcher to start watching for changes again\n // by signaling that notifications have been flushed.\n state.watcher.watch();\n}\n\nfunction _createWatcher() {\n const id = watcherId++;\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n console.log(`[WarpDrive] Creating a WatcherContext:${id}`);\n }\n const state: WatcherState = {\n watcherId: id,\n pending: false,\n destroyed: false,\n notifyReact: null as (() => void) | null,\n watcher: null as unknown as Signal.subtle.Watcher,\n\n // the extra wrapper returned here ensures that the context value for the watcher\n // changes causing a re-render when the watcher is updated.\n snapshot: null as { watcher: Signal.subtle.Watcher } | null,\n };\n\n state.watcher = new Signal.subtle.Watcher((...args) => {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n console.log(`watcher ${state.watcherId} notified`, args, state.watcher);\n }\n if (!state.pending && !state.destroyed) {\n watchers.push(state);\n state.pending = true;\n\n if (!nextFlush) {\n nextFlush = new Promise((resolve) => {\n queueMicrotask(() => {\n queueMicrotask(() => {\n queueMicrotask(() => {\n watchers.forEach(flush);\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n console.log(\n \"Flushed watcher:\",\n watchers.map((w) => w.watcherId)\n );\n }\n watchers = [];\n nextFlush = null;\n\n resolve();\n });\n });\n });\n });\n }\n } else if (state.destroyed) {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n console.log(`[WarpDrive] Detected Watcher Destroyed During Notify, clearing signals`);\n }\n // if we are destroyed, we clear the watcher signals\n // so that it does not continue to watch for changes.\n state.snapshot = null;\n clearWatcher(state);\n }\n });\n\n // The watcher won't begin watching until we call `watcher.watch()`\n state.watcher.watch();\n state.snapshot = { watcher: state.watcher };\n\n return state;\n}\n\nexport function useWatcher(): { watcher: Signal.subtle.Watcher } | null {\n const state = useMemo(_createWatcher, []);\n\n return useSyncExternalStore(\n (notifyChanged: () => void) => {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n console.log(`[WarpDrive] Subscribing to Watcher`);\n }\n state.destroyed = false;\n state.notifyReact = notifyChanged;\n\n // The watcher won't begin watching until we call `watcher.watch()`\n state.watcher.watch();\n\n return () => {\n if (LOG_REACT_SIGNAL_INTEGRATION) {\n console.log(`[WarpDrive] Deactivating Watcher Subscription`);\n }\n state.destroyed = true;\n state.notifyReact = null;\n };\n },\n () => state.snapshot\n );\n}\n\n/**\n * @category Contexts\n */\nexport const WatcherContext: Context<{\n /**\n * The `Signal.subtle.Watcher` used to observe signal changes for the nearest {@link ReactiveContext}.\n */\n watcher: Signal.subtle.Watcher;\n} | null> = createContext<{\n watcher: Signal.subtle.Watcher;\n} | null>(null);\n\n/**\n *\n * @category Components\n */\nexport function ReactiveContext({ children }: { children: ReactNode }): JSX.Element {\n const watcher = useWatcher();\n /**\n * Unlike other frameworks, React does not have a built-in way to provide\n * a context value other than by rendering an extra component.\n *\n */\n return <WatcherContext value={watcher}>{children}</WatcherContext>;\n}\n"],"mappings":";;;;;;AAIA,IAAIQ,YAAkC;AACtC,IAAIC,WAA2B,CAAA;AAC/B,IAAIC,YAAY;AAchB,SAASC,aAAaC,OAAqB;CACzCA,MAAMC,QAAQC,QAAQ,GAAGd,OAAOe,OAAOC,kBAAkBJ,MAAMC,OAAO,CAAC;AACzE;AAEA,SAASI,MAAML,OAAqB;CAClCA,MAAMM,UAAU;CAChB,IAAIN,MAAMO,WAAW;EACnB,IAAAd,eAAAD,gBAAA,CAAA,CAAAgB,UAAAC,cAAAC,4BAAA,GAAA;OAAAlB,gBAAA,CAAA,CAAAgB,UAAAG,MAAAD,gCAAAE,WAAAC,0BAAA,CAAA,CAAAF,MAAAD,8BACEI,QAAQC,IAAI,8EAA8E;EAC5F;EACAf,MAAMgB,WAAW;EACjBjB,aAAaC,KAAK;EAClB;CACF;CAEA,IAAAP,eAAAD,gBAAA,CAAA,CAAAgB,UAAAC,cAAAC,4BAAA,GAAA;MAAAlB,gBAAA,CAAA,CAAAgB,UAAAG,MAAAD,gCAAAE,WAAAC,0BAAA,CAAA,CAAAF,MAAAD,8BAAkC;GAChCI,QAAQC,IAAI,mDAAmDf,MAAMF,UAAS,aAAc;GAC5FgB,QAAQC,IAAI,eAAe,IAAIE,IAAI7B,OAAOe,OAAOC,kBAAkBJ,MAAMC,OAAO,CAAC,CAAC;GAClFa,QAAQC,IAAI,iBAAiB,IAAIE,IAAIjB,MAAMC,QAAQiB,WAAW,CAAC,CAAC;EAClE;;CAGAlB,MAAMgB,WAAW,EAAEf,SAASD,MAAMC,QAAQ;CAC1C,IAAID,MAAMmB,aAAanB,MAAMmB,YAAY;CAIzC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