@warp-drive/react 5.9.0-alpha.9 → 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-CTtwoaBx.js +0 -290
  41. package/dist/unpkg/dev-deprecated/reactive-context-sqyJMb7I.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,110 +0,0 @@
1
- import { Signal } from 'signal-polyfill';
2
- import { createContext, useMemo, useSyncExternalStore } from 'react';
3
- import { jsx } from 'react/jsx-runtime';
4
- let nextFlush = null;
5
- let watchers = [];
6
- let watcherId = 0;
7
- function clearWatcher(state) {
8
- state.watcher.unwatch(...Signal.subtle.introspectSources(state.watcher));
9
- }
10
- function flush(state) {
11
- state.pending = false;
12
- if (state.destroyed) {
13
- state.snapshot = null;
14
- clearWatcher(state);
15
- return;
16
- }
17
- // any time signals have changed, we notify React that our store has updated
18
- state.snapshot = {
19
- watcher: state.watcher
20
- };
21
- if (state.notifyReact) state.notifyReact();
22
-
23
- // tell the Watcher to start watching for changes again
24
- // by signaling that notifications have been flushed.
25
- state.watcher.watch();
26
- }
27
- function _createWatcher() {
28
- const id = watcherId++;
29
- const state = {
30
- watcherId: id,
31
- pending: false,
32
- destroyed: false,
33
- notifyReact: null,
34
- watcher: null,
35
- // the extra wrapper returned here ensures that the context value for the watcher
36
- // changes causing a re-render when the watcher is updated.
37
- snapshot: null
38
- };
39
- state.watcher = new Signal.subtle.Watcher((...args) => {
40
- if (!state.pending && !state.destroyed) {
41
- watchers.push(state);
42
- state.pending = true;
43
- if (!nextFlush) {
44
- nextFlush = new Promise(resolve => {
45
- queueMicrotask(() => {
46
- queueMicrotask(() => {
47
- queueMicrotask(() => {
48
- watchers.forEach(flush);
49
- watchers = [];
50
- nextFlush = null;
51
- resolve();
52
- });
53
- });
54
- });
55
- });
56
- }
57
- } else if (state.destroyed) {
58
- // if we are destroyed, we clear the watcher signals
59
- // so that it does not continue to watch for changes.
60
- state.snapshot = null;
61
- clearWatcher(state);
62
- }
63
- });
64
-
65
- // The watcher won't begin watching until we call `watcher.watch()`
66
- state.watcher.watch();
67
- state.snapshot = {
68
- watcher: state.watcher
69
- };
70
- return state;
71
- }
72
- function useWatcher() {
73
- const state = useMemo(_createWatcher, []);
74
- return useSyncExternalStore(notifyChanged => {
75
- state.destroyed = false;
76
- state.notifyReact = notifyChanged;
77
-
78
- // The watcher won't begin watching until we call `watcher.watch()`
79
- state.watcher.watch();
80
- return () => {
81
- state.destroyed = true;
82
- state.notifyReact = null;
83
- };
84
- }, () => state.snapshot);
85
- }
86
-
87
- /**
88
- * @category Contexts
89
- */
90
- const WatcherContext = /*#__PURE__*/createContext(null);
91
-
92
- /**
93
- *
94
- * @category Components
95
- */
96
- function ReactiveContext({
97
- children
98
- }) {
99
- const watcher = useWatcher();
100
- /**
101
- * Unlike other frameworks, React does not have a built-in way to provide
102
- * a context value other than by rendering an extra component.
103
- *
104
- */
105
- return /*#__PURE__*/jsx(WatcherContext, {
106
- value: watcher,
107
- children: children
108
- });
109
- }
110
- export { ReactiveContext as R, WatcherContext as W };