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

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 (46) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/index.d.ts +180 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +216 -251
  5. package/dist/index.js.map +1 -0
  6. package/dist/install.d.ts +21 -0
  7. package/dist/install.d.ts.map +1 -0
  8. package/dist/install.js +90 -94
  9. package/dist/install.js.map +1 -0
  10. package/dist/reactive-context-DhUW_l--.js +122 -0
  11. package/dist/reactive-context-DhUW_l--.js.map +1 -0
  12. package/dist/unpkg/dev/index.js +260 -299
  13. package/dist/unpkg/dev/index.js.map +1 -0
  14. package/dist/unpkg/dev/install.js +82 -92
  15. package/dist/unpkg/dev/install.js.map +1 -0
  16. package/dist/unpkg/dev/reactive-context-Ax2U-96G.js +218 -0
  17. package/dist/unpkg/dev/reactive-context-Ax2U-96G.js.map +1 -0
  18. package/dist/unpkg/dev-deprecated/index.js +260 -299
  19. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  20. package/dist/unpkg/dev-deprecated/install.js +82 -92
  21. package/dist/unpkg/dev-deprecated/install.js.map +1 -0
  22. package/dist/unpkg/dev-deprecated/reactive-context-B-pn7tS7.js +218 -0
  23. package/dist/unpkg/dev-deprecated/reactive-context-B-pn7tS7.js.map +1 -0
  24. package/dist/unpkg/prod/index.js +199 -226
  25. package/dist/unpkg/prod/index.js.map +1 -0
  26. package/dist/unpkg/prod/install.js +56 -48
  27. package/dist/unpkg/prod/install.js.map +1 -0
  28. package/dist/unpkg/prod/reactive-context-eAEvPuqb.js +92 -0
  29. package/dist/unpkg/prod/reactive-context-eAEvPuqb.js.map +1 -0
  30. package/dist/unpkg/prod-deprecated/index.js +199 -226
  31. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  32. package/dist/unpkg/prod-deprecated/install.js +56 -48
  33. package/dist/unpkg/prod-deprecated/install.js.map +1 -0
  34. package/dist/unpkg/prod-deprecated/reactive-context-eAEvPuqb.js +92 -0
  35. package/dist/unpkg/prod-deprecated/reactive-context-eAEvPuqb.js.map +1 -0
  36. package/package.json +25 -33
  37. package/declarations/-private/reactive-context.d.ts +0 -18
  38. package/declarations/-private/request.d.ts +0 -142
  39. package/declarations/-private/store-provider.d.ts +0 -19
  40. package/declarations/index.d.ts +0 -7
  41. package/declarations/install.d.ts +0 -3
  42. package/dist/reactive-context-ClTRYXie.js +0 -154
  43. package/dist/unpkg/dev/reactive-context-B815u0_c.js +0 -290
  44. package/dist/unpkg/dev-deprecated/reactive-context-DMgQ7YV_.js +0 -290
  45. package/dist/unpkg/prod/reactive-context-DKimDkR3.js +0 -110
  46. package/dist/unpkg/prod-deprecated/reactive-context-DKimDkR3.js +0 -110
@@ -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 };
@@ -1,290 +0,0 @@
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": false
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().WarpDrive.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().WarpDrive.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().WarpDrive.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().WarpDrive.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().WarpDrive.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().WarpDrive.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().WarpDrive.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().WarpDrive.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 };