@warp-drive/react 5.9.0-beta.0 → 5.9.0-beta.1

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 (43) hide show
  1. package/declarations/index.d.ts +179 -6
  2. package/declarations/index.d.ts.map +1 -0
  3. package/declarations/install.d.ts +21 -3
  4. package/declarations/install.d.ts.map +1 -0
  5. package/dist/index.js +216 -251
  6. package/dist/index.js.map +1 -0
  7. package/dist/install.js +90 -94
  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 +260 -299
  12. package/dist/unpkg/dev/index.js.map +1 -0
  13. package/dist/unpkg/dev/install.js +82 -92
  14. package/dist/unpkg/dev/install.js.map +1 -0
  15. package/dist/unpkg/dev/reactive-context-C9-Fc8qx.js +218 -0
  16. package/dist/unpkg/dev/reactive-context-C9-Fc8qx.js.map +1 -0
  17. package/dist/unpkg/dev-deprecated/index.js +260 -299
  18. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  19. package/dist/unpkg/dev-deprecated/install.js +82 -92
  20. package/dist/unpkg/dev-deprecated/install.js.map +1 -0
  21. package/dist/unpkg/dev-deprecated/reactive-context-DhpCE2Tv.js +218 -0
  22. package/dist/unpkg/dev-deprecated/reactive-context-DhpCE2Tv.js.map +1 -0
  23. package/dist/unpkg/prod/index.js +199 -226
  24. package/dist/unpkg/prod/index.js.map +1 -0
  25. package/dist/unpkg/prod/install.js +56 -48
  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 +199 -226
  30. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  31. package/dist/unpkg/prod-deprecated/install.js +56 -48
  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 +14 -15
  36. package/declarations/-private/reactive-context.d.ts +0 -18
  37. package/declarations/-private/request.d.ts +0 -142
  38. package/declarations/-private/store-provider.d.ts +0 -19
  39. package/dist/reactive-context-ClTRYXie.js +0 -154
  40. package/dist/unpkg/dev/reactive-context-B815u0_c.js +0 -290
  41. package/dist/unpkg/dev-deprecated/reactive-context-DMgQ7YV_.js +0 -290
  42. package/dist/unpkg/prod/reactive-context-DKimDkR3.js +0 -110
  43. package/dist/unpkg/prod-deprecated/reactive-context-DKimDkR3.js +0 -110
@@ -1,56 +1,64 @@
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-DKimDkR3.js";
1
+ import { n as WatcherContext } from "./reactive-context-CvfXAZqb.js";
2
+ import { Signal } from "signal-polyfill";
3
+ import { use } from "react";
4
+ import { setupSignals } from "@warp-drive/core/configure";
5
5
 
6
+ //#region src/install.ts
6
7
  /**
7
- * {@include ./install.md}
8
- * @module
9
- */
10
-
8
+ * {@include ./install.md}
9
+ * @module
10
+ */
11
11
  function tryConsumeContext(signal) {
12
- // eslint-disable-next-line no-console
13
- const logError = console.error;
14
- try {
15
- // eslint-disable-next-line no-console
16
- console.error = () => {};
17
- // ensure signals are watched by our closest watcher
18
- const watcher = use(WatcherContext);
19
- // eslint-disable-next-line no-console
20
- console.error = logError;
21
- watcher?.watcher.watch(signal);
22
- } catch {
23
- // eslint-disable-next-line no-console
24
- console.error = logError;
25
- // if we are not in a React context, we will Error
26
- // so we just ignore it.
27
- }
12
+ const logError = console.error;
13
+ try {
14
+ console.error = () => {};
15
+ const watcher = use(WatcherContext);
16
+ console.error = logError;
17
+ watcher?.watcher.watch(signal);
18
+ } catch {
19
+ console.error = logError;
20
+ }
28
21
  }
22
+ /**
23
+ * Resolves once all pending requests started via WarpDrive's React signal
24
+ * integration have settled. Only tracks requests while `TESTING` is enabled;
25
+ * a no-op otherwise.
26
+ *
27
+ * @public
28
+ */
29
29
  async function settled() {}
30
+ /**
31
+ * Builds the {@link SignalHooks} implementation backed by the
32
+ * [Signal Polyfill](https://github.com/proposal-signals/signal-polyfill),
33
+ * used to wire WarpDrive's reactivity primitives into React.
34
+ *
35
+ * @public
36
+ */
30
37
  function buildSignalConfig(options) {
31
- return {
32
- createSignal: (obj, key) => new Signal.State(null, {
33
- equals: () => false
34
- }),
35
- notifySignal: signal => {
36
- signal.set(signal.get());
37
- },
38
- consumeSignal: signal => {
39
- tryConsumeContext(signal);
40
- void signal.get();
41
- },
42
- createMemo: (object, key, fn) => {
43
- const memo = new Signal.Computed(fn);
44
- return () => {
45
- tryConsumeContext(memo);
46
- return memo.get();
47
- };
48
- },
49
- waitFor: promise => {
50
- return promise;
51
- },
52
- willSyncFlushWatchers: () => false
53
- };
38
+ return {
39
+ createSignal: (obj, key) => new Signal.State(null, { equals: () => false }),
40
+ notifySignal: (signal) => {
41
+ signal.set(signal.get());
42
+ },
43
+ consumeSignal: (signal) => {
44
+ tryConsumeContext(signal);
45
+ signal.get();
46
+ },
47
+ createMemo: (object, key, fn) => {
48
+ const memo = new Signal.Computed(fn);
49
+ return () => {
50
+ tryConsumeContext(memo);
51
+ return memo.get();
52
+ };
53
+ },
54
+ waitFor: (promise) => {
55
+ return promise;
56
+ },
57
+ willSyncFlushWatchers: () => false
58
+ };
54
59
  }
55
60
  setupSignals(buildSignalConfig);
56
- export { buildSignalConfig, settled };
61
+
62
+ //#endregion
63
+ export { buildSignalConfig, settled };
64
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","names":["use","Signal","setupSignals","WatcherContext","tryConsumeContext","signal","logError","console","error","watcher","watch","pending","settled","buildSignalConfig","options","createSignal","obj","key","State","equals","notifySignal","set","get","consumeSignal","createMemo","object","fn","memo","Computed","waitFor","promise","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 willSyncFlushWatchers: () => false,\n } as SignalHooks;\n}\n\nsetupSignals(buildSignalConfig);\n"],"mappings":";;;;;;;;;;AAcA,SAASI,kBAAkBC,QAAgE;CAEzF,MAAMC,WAAWC,QAAQC;CACzB,IAAI;EAEFD,QAAQC,cAAc,CAAC;EAEvB,MAAMC,UAAUT,IAAIG,cAAc;EAElCI,QAAQC,QAAQF;EAChBG,SAASA,QAAQC,MAAML,MAAM;CAK/B,QAAQ;EAENE,QAAQC,QAAQF;CAOlB;AACF;;;;;;;;AAUA,eAAsBM,UAAyB,CAa/C;;;;;;;;AASA,SAAgBC,kBAAkBC,SAAoC;CACpE,OAAO;EACLC,eAAeC,KAAaC,QAC1B,IAAIhB,OAAOiB,MAA6B,MAAM,EAAEC,cAAc,MAAM,CAAC;EAEvEC,eAAef,WAAkC;GAU/CA,OAAOgB,IAAIhB,OAAOiB,IAAI,CAAC;EACzB;EAEAC,gBAAgBlB,WAAkC;GAChDD,kBAAkBC,MAAM;GACxB,AAAKA,OAAOiB,IAAI;EAClB;EAEAE,aAAgBC,QAAgBR,KAAsBS,OAA2B;GAC/E,MAAMC,OAAO,IAAI1B,OAAO2B,SAAYF,EAAE;GACtC,aAAa;IACXtB,kBAAkBuB,IAAI;IAEtB,OAAOA,KAAKL,IAAI;GAClB;EACF;EAEAO,UAAUC,YAAY;GASpB,OAAOA;EACT;EAEAC,6BAA6B;CAC/B;AACF;AAEA7B,aAAaW,iBAAiB"}
@@ -0,0 +1,92 @@
1
+ import { Signal } from "signal-polyfill";
2
+ import { createContext, useMemo, useSyncExternalStore } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+
5
+ //#region src/-private/reactive-context.tsx
6
+ let nextFlush = null;
7
+ let watchers = [];
8
+ let watcherId = 0;
9
+ function clearWatcher(state) {
10
+ state.watcher.unwatch(...Signal.subtle.introspectSources(state.watcher));
11
+ }
12
+ function flush(state) {
13
+ state.pending = false;
14
+ if (state.destroyed) {
15
+ state.snapshot = null;
16
+ clearWatcher(state);
17
+ return;
18
+ }
19
+ state.snapshot = { watcher: state.watcher };
20
+ if (state.notifyReact) state.notifyReact();
21
+ state.watcher.watch();
22
+ }
23
+ function _createWatcher() {
24
+ const state = {
25
+ watcherId: watcherId++,
26
+ pending: false,
27
+ destroyed: false,
28
+ notifyReact: null,
29
+ watcher: null,
30
+ snapshot: null
31
+ };
32
+ state.watcher = new Signal.subtle.Watcher((...args) => {
33
+ if (!state.pending && !state.destroyed) {
34
+ watchers.push(state);
35
+ state.pending = true;
36
+ if (!nextFlush) nextFlush = new Promise((resolve) => {
37
+ queueMicrotask(() => {
38
+ queueMicrotask(() => {
39
+ queueMicrotask(() => {
40
+ watchers.forEach(flush);
41
+ watchers = [];
42
+ nextFlush = null;
43
+ resolve();
44
+ });
45
+ });
46
+ });
47
+ });
48
+ } else if (state.destroyed) {
49
+ state.snapshot = null;
50
+ clearWatcher(state);
51
+ }
52
+ });
53
+ state.watcher.watch();
54
+ state.snapshot = { watcher: state.watcher };
55
+ return state;
56
+ }
57
+ function useWatcher() {
58
+ const state = useMemo(_createWatcher, []);
59
+ return useSyncExternalStore((notifyChanged) => {
60
+ state.destroyed = false;
61
+ state.notifyReact = notifyChanged;
62
+ state.watcher.watch();
63
+ return () => {
64
+ state.destroyed = true;
65
+ state.notifyReact = null;
66
+ };
67
+ }, () => state.snapshot);
68
+ }
69
+ /**
70
+ * @category Contexts
71
+ */
72
+ const WatcherContext = /*#__PURE__*/ createContext(null);
73
+ /**
74
+ *
75
+ * @category Components
76
+ */
77
+ function ReactiveContext({ children }) {
78
+ const watcher = useWatcher();
79
+ /**
80
+ * Unlike other frameworks, React does not have a built-in way to provide
81
+ * a context value other than by rendering an extra component.
82
+ *
83
+ */
84
+ return /*#__PURE__*/ jsx(WatcherContext, {
85
+ value: watcher,
86
+ children
87
+ });
88
+ }
89
+
90
+ //#endregion
91
+ export { WatcherContext as n, ReactiveContext as t };
92
+ //# sourceMappingURL=reactive-context-CvfXAZqb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive-context-CvfXAZqb.js","names":["Signal","createContext","useSyncExternalStore","useMemo","jsx","_jsx","nextFlush","watchers","watcherId","clearWatcher","state","watcher","unwatch","subtle","introspectSources","flush","pending","destroyed","snapshot","notifyReact","watch","_createWatcher","id","Watcher","args","push","Promise","resolve","queueMicrotask","forEach","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,IAAIM,YAAkC;AACtC,IAAIC,WAA2B,CAAA;AAC/B,IAAIC,YAAY;AAchB,SAASC,aAAaC,OAAqB;CACzCA,MAAMC,QAAQC,QAAQ,GAAGZ,OAAOa,OAAOC,kBAAkBJ,MAAMC,OAAO,CAAC;AACzE;AAEA,SAASI,MAAML,OAAqB;CAClCA,MAAMM,UAAU;CAChB,IAAIN,MAAMO,WAAW;EAInBP,MAAMQ,WAAW;EACjBT,aAAaC,KAAK;EAClB;CACF;CASAA,MAAMQ,WAAW,EAAEP,SAASD,MAAMC,QAAQ;CAC1C,IAAID,MAAMS,aAAaT,MAAMS,YAAY;CAIzCT,MAAMC,QAAQS,MAAM;AACtB;AAEA,SAASC,iBAAiB;CAKxB,MAAMX,QAAsB;EAC1BF,WAAWc,AALFd;EAMTQ,SAAS;EACTC,WAAW;EACXE,aAAa;EACbR,SAAS;EAITO,UAAU;CACZ;CAEAR,MAAMC,UAAU,IAAIX,OAAOa,OAAOU,SAAS,GAAGC,SAAS;EAIrD,IAAI,CAACd,MAAMM,WAAW,CAACN,MAAMO,WAAW;GACtCV,SAASkB,KAAKf,KAAK;GACnBA,MAAMM,UAAU;GAEhB,IAAI,CAACV,WACHA,YAAY,IAAIoB,SAASC,YAAY;IACnCC,qBAAqB;KACnBA,qBAAqB;MACnBA,qBAAqB;OACnBrB,SAASsB,QAAQd,KAAK;OAOtBR,WAAW,CAAA;OACXD,YAAY;OAEZqB,QAAQ;MACV,CAAC;KACH,CAAC;IACH,CAAC;GACH,CAAC;EAEL,OAAO,IAAIjB,MAAMO,WAAW;GAM1BP,MAAMQ,WAAW;GACjBT,aAAaC,KAAK;EACpB;CACF,CAAC;CAGDA,MAAMC,QAAQS,MAAM;CACpBV,MAAMQ,WAAW,EAAEP,SAASD,MAAMC,QAAQ;CAE1C,OAAOD;AACT;AAEA,SAAgBoB,aAAwD;CACtE,MAAMpB,QAAQP,QAAQkB,gBAAgB,CAAA,CAAE;CAExC,OAAOnB,sBACJ6B,kBAA8B;EAI7BrB,MAAMO,YAAY;EAClBP,MAAMS,cAAcY;EAGpBrB,MAAMC,QAAQS,MAAM;EAEpB,aAAa;GAIXV,MAAMO,YAAY;GAClBP,MAAMS,cAAc;EACtB;CACF,SACMT,MAAMQ,QACd;AACF;;;;AAKA,MAAac,iBAKD/B,4BAEF,IAAI;;;;;AAMd,SAAgBgC,gBAAgB,EAAEC,YAAkD;CAClF,MAAMvB,UAAUmB,WAAW;;;;;;CAM3B,OAAOzB,kBAAC2B,gBAAc;EAACG,OAAOxB;EAAUuB;CAAQ,CAAiB;AACnE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@warp-drive/react",
3
3
  "description": "Data bindings and utilities for React applications using WarpDrive",
4
- "version": "5.9.0-beta.0",
4
+ "version": "5.9.0-beta.1",
5
5
  "license": "MIT",
6
6
  "author": "Chris Thoburn <runspired@users.noreply.github.com>",
7
7
  "repository": {
@@ -43,31 +43,30 @@
43
43
  "default": "./dist/*.js"
44
44
  }
45
45
  },
46
- "peerDependencies": {},
47
46
  "dependencies": {
48
- "@embroider/macros": "^1.18.1",
49
- "@warp-drive/core": "5.9.0-beta.0",
50
- "@warp-drive/tc39-proposal-signals": "5.9.0-beta.0",
51
- "signal-polyfill": "^0.2.2",
52
- "react": "^19.1.1"
47
+ "@embroider/macros": "^1.20.6",
48
+ "@warp-drive/core": "5.9.0-beta.1",
49
+ "@warp-drive/tc39-proposal-signals": "5.9.0-beta.1",
50
+ "react": "^19.1.1",
51
+ "signal-polyfill": "^0.2.2"
53
52
  },
54
53
  "peerDependenciesMeta": {},
55
54
  "devDependencies": {
56
55
  "@babel/core": "^7.28.3",
57
56
  "@babel/plugin-transform-typescript": "^7.28.0",
58
57
  "@babel/preset-env": "^7.28.3",
59
- "@babel/preset-typescript": "^7.27.1",
60
58
  "@babel/preset-react": "^7.27.1",
59
+ "@babel/preset-typescript": "^7.27.1",
61
60
  "@babel/runtime": "^7.28.3",
62
- "decorator-transforms": "^2.3.0",
63
61
  "@embroider/addon-dev": "^8.1.0",
64
- "@warp-drive/internal-config": "5.9.0-beta.0",
65
- "@warp-drive/core": "5.9.0-beta.0",
66
62
  "@types/react": "^19.1.11",
63
+ "@warp-drive/core": "5.9.0-beta.1",
64
+ "@warp-drive/internal-config": "5.9.0-beta.1",
65
+ "decorator-transforms": "^2.3.0",
67
66
  "react": "^19.1.1",
68
67
  "rollup": "^4.48.0",
69
- "typescript": "^5.9.2",
70
- "vite": "^7.1.3"
68
+ "tsdown": "^0.22.14",
69
+ "typescript": "^5.9.3"
71
70
  },
72
71
  "volta": {
73
72
  "extends": "../../package.json"
@@ -82,9 +81,9 @@
82
81
  "edition": "octane"
83
82
  },
84
83
  "scripts": {
85
- "build:pkg": "vite build;",
84
+ "build:pkg": "NODE_ENV=production tsdown",
86
85
  "sync": "echo \"syncing\"",
87
86
  "lint": "eslint . --quiet --cache --cache-strategy=content",
88
- "start": "vite"
87
+ "start": "tsdown --watch"
89
88
  }
90
89
  }
@@ -1,18 +0,0 @@
1
- import { Signal } from "signal-polyfill";
2
- import { type JSX, type ReactNode, type Context } from "react";
3
- export declare function useWatcher(): {
4
- watcher: Signal.subtle.Watcher;
5
- } | null;
6
- /**
7
- * @category Contexts
8
- */
9
- export declare const WatcherContext: Context<{
10
- watcher: Signal.subtle.Watcher;
11
- } | null>;
12
- /**
13
- *
14
- * @category Components
15
- */
16
- export declare function ReactiveContext({ children }: {
17
- children: ReactNode;
18
- }): JSX.Element;
@@ -1,142 +0,0 @@
1
- import { type RequestLoadingState, type RequestState } from "@warp-drive/core/reactive";
2
- import { RequestArgs, type ContentFeatures, type RecoveryFeatures } from "@warp-drive/core/signals/-leaked";
3
- import type { StructuredErrorDocument } from "@warp-drive/core/types/request";
4
- import { JSX, ReactNode } from "react";
5
- interface ChromeComponentProps<RT> {
6
- children: ReactNode;
7
- state: RequestState | null;
8
- features: ContentFeatures<RT>;
9
- }
10
- export interface RequestProps<
11
- RT,
12
- E
13
- > extends RequestArgs<RT, E> {
14
- chrome?: React.FC<ChromeComponentProps<RT>>;
15
- states: RequestStates<RT, E>;
16
- }
17
- interface RequestStates<
18
- RT,
19
- E
20
- > {
21
- /**
22
- * The block to render when the component is idle and waiting to be given a request.
23
- *
24
- */
25
- idle?: React.FC<{}>;
26
- /**
27
- * The block to render when the request is loading.
28
- *
29
- */
30
- loading?: React.FC<{
31
- state: RequestLoadingState;
32
- }>;
33
- /**
34
- * The block to render when the request was cancelled.
35
- *
36
- */
37
- cancelled?: React.FC<{
38
- /**
39
- * The Error the request rejected with.
40
- */
41
- error: StructuredErrorDocument<E>;
42
- /**
43
- * Utilities to assist in recovering from the error.
44
- */
45
- features: RecoveryFeatures;
46
- }>;
47
- /**
48
- * The block to render when the request failed. If this block is not provided,
49
- * the error will be rethrown.
50
- *
51
- * Thus it is required to provide an error block and proper error handling if
52
- * you do not want the error to crash the application.
53
- */
54
- error: React.FC<{
55
- /**
56
- * The Error the request rejected with.
57
- */
58
- error: StructuredErrorDocument<E>;
59
- /**
60
- * Utilities to assist in recovering from the error.
61
- */
62
- features: RecoveryFeatures;
63
- }>;
64
- /**
65
- * The block to render when the request succeeded.
66
- *
67
- */
68
- content: React.FC<{
69
- result: RT;
70
- features: ContentFeatures<RT>;
71
- }>;
72
- }
73
- export declare function Throw({ error }: {
74
- error: Error;
75
- }): never;
76
- /**
77
- * The `<Request />` component is a powerful tool for managing data fetching and
78
- * state in your React application. It provides a declarative approach to reactive
79
- * control-flow for managing requests and state in your application.
80
- *
81
- * The `<Request />` component is ideal for handling "boundaries", outside which some
82
- * state is still allowed to be unresolved and within which it MUST be resolved.
83
- *
84
- * ## Request States
85
- *
86
- * `<Request />` has five states, only one of which will be active and rendered at a time.
87
- *
88
- * - `idle`: The component is waiting to be given a request to monitor
89
- * - `loading`: The request is in progress
90
- * - `error`: The request failed
91
- * - `content`: The request succeeded
92
- * - `cancelled`: The request was cancelled
93
- *
94
- * Additionally, the `content` state has a `refresh` method that can be used to
95
- * refresh the request in the background, which is available as a sub-state of
96
- * the `content` state.
97
- *
98
- * ### Example Usage
99
- *
100
- * ```tsx
101
- * import { Request } from "@warp-drive/react";
102
- *
103
- * export function UserPreview($props: { id: string | null }) {
104
- * return (
105
- * <Request
106
- * query={findRecord('user', $props.id)}
107
- * states={{
108
- * idle: () => <div>Waiting for User Selection</div>,
109
- * loading: ({ state }) => <div>Loading user data...</div>,
110
- * cancelled: ({ error, features }) => (
111
- * <div>
112
- * <p>Request Cancelled</p>
113
- * <p><button onClick={features.retry}>Start Again?</button></p>
114
- * </div>
115
- * ),
116
- * error: ({ error, features }) => (
117
- * <div>
118
- * <p>Error: {error.message}</p>
119
- * <p><button onClick={features.retry}>Try Again?</button></p>
120
- * </div>
121
- * ),
122
- * content: ({ result, features }) => (
123
- * <div>
124
- * <h2>User Details</h2>
125
- * <p>ID: {result.id}</p>
126
- * <p>Name: {result.name}</p>
127
- * </div>
128
- * ),
129
- * }}
130
- * />
131
- * );
132
- * }
133
- *
134
- * ```
135
- *
136
- * @category Components
137
- */
138
- export declare function Request<
139
- RT,
140
- E
141
- >($props: RequestProps<RT, E>): JSX.Element;
142
- export {};
@@ -1,19 +0,0 @@
1
- import { Store } from "@warp-drive/core";
2
- import { JSX, ReactNode } from "react";
3
- /**
4
- * @category Hooks
5
- */
6
- export declare function useStore(): Store;
7
- type WithExistingStore = {
8
- store: Store;
9
- children: ReactNode;
10
- };
11
- type WithNewStore = {
12
- Store: typeof Store;
13
- children: ReactNode;
14
- };
15
- /**
16
- * @category Components
17
- */
18
- export declare function StoreProvider($props: WithExistingStore | WithNewStore): JSX.Element;
19
- export {};
@@ -1,154 +0,0 @@
1
- import { Signal } from 'signal-polyfill';
2
- import { createContext, useMemo, useSyncExternalStore } from 'react';
3
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
- import { jsx } from 'react/jsx-runtime';
5
- let nextFlush = null;
6
- let watchers = [];
7
- let watcherId = 0;
8
- function clearWatcher(state) {
9
- state.watcher.unwatch(...Signal.subtle.introspectSources(state.watcher));
10
- }
11
- function flush(state) {
12
- state.pending = false;
13
- if (state.destroyed) {
14
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
15
- if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
16
- console.log(`[WarpDrive] Detected Watcher Destroyed During Notify Flush, clearing signals`);
17
- }
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
-
31
- // any time signals have changed, we notify React that our store has updated
32
- state.snapshot = {
33
- watcher: state.watcher
34
- };
35
- if (state.notifyReact) state.notifyReact();
36
-
37
- // tell the Watcher to start watching for changes again
38
- // by signaling that notifications have been flushed.
39
- state.watcher.watch();
40
- }
41
- function _createWatcher() {
42
- const id = watcherId++;
43
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
44
- if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
45
- console.log(`[WarpDrive] Creating a WatcherContext:${id}`);
46
- }
47
- }
48
- const state = {
49
- watcherId: id,
50
- pending: false,
51
- destroyed: false,
52
- notifyReact: null,
53
- watcher: null,
54
- // the extra wrapper returned here ensures that the context value for the watcher
55
- // changes causing a re-render when the watcher is updated.
56
- snapshot: null
57
- };
58
- state.watcher = new Signal.subtle.Watcher((...args) => {
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) {
61
- console.log(`watcher ${state.watcherId} notified`, args, state.watcher);
62
- }
63
- }
64
- if (!state.pending && !state.destroyed) {
65
- watchers.push(state);
66
- state.pending = true;
67
- if (!nextFlush) {
68
- nextFlush = new Promise(resolve => {
69
- queueMicrotask(() => {
70
- queueMicrotask(() => {
71
- queueMicrotask(() => {
72
- watchers.forEach(flush);
73
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
74
- if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
75
- console.log("Flushed watcher:", watchers.map(w => w.watcherId));
76
- }
77
- }
78
- watchers = [];
79
- nextFlush = null;
80
- resolve();
81
- });
82
- });
83
- });
84
- });
85
- }
86
- } else if (state.destroyed) {
87
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
88
- if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
89
- console.log(`[WarpDrive] Detected Watcher Destroyed During Notify, clearing signals`);
90
- }
91
- }
92
- // if we are destroyed, we clear the watcher signals
93
- // so that it does not continue to watch for changes.
94
- state.snapshot = null;
95
- clearWatcher(state);
96
- }
97
- });
98
-
99
- // The watcher won't begin watching until we call `watcher.watch()`
100
- state.watcher.watch();
101
- state.snapshot = {
102
- watcher: state.watcher
103
- };
104
- return state;
105
- }
106
- function useWatcher() {
107
- const state = useMemo(_createWatcher, []);
108
- return useSyncExternalStore(notifyChanged => {
109
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
110
- if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
111
- console.log(`[WarpDrive] Subscribing to Watcher`);
112
- }
113
- }
114
- state.destroyed = false;
115
- state.notifyReact = notifyChanged;
116
-
117
- // The watcher won't begin watching until we call `watcher.watch()`
118
- state.watcher.watch();
119
- return () => {
120
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_REACT_SIGNAL_INTEGRATION)) {
121
- if (getGlobalConfig().WarpDrive.debug.LOG_REACT_SIGNAL_INTEGRATION || globalThis.getWarpDriveRuntimeConfig().debug.LOG_REACT_SIGNAL_INTEGRATION) {
122
- console.log(`[WarpDrive] Deactivating Watcher Subscription`);
123
- }
124
- }
125
- state.destroyed = true;
126
- state.notifyReact = null;
127
- };
128
- }, () => state.snapshot);
129
- }
130
-
131
- /**
132
- * @category Contexts
133
- */
134
- const WatcherContext = /*#__PURE__*/createContext(null);
135
-
136
- /**
137
- *
138
- * @category Components
139
- */
140
- function ReactiveContext({
141
- children
142
- }) {
143
- const watcher = useWatcher();
144
- /**
145
- * Unlike other frameworks, React does not have a built-in way to provide
146
- * a context value other than by rendering an extra component.
147
- *
148
- */
149
- return /*#__PURE__*/jsx(WatcherContext, {
150
- value: watcher,
151
- children: children
152
- });
153
- }
154
- export { ReactiveContext as R, WatcherContext as W };