@warp-drive/core 5.8.0-alpha.40 → 5.8.0-alpha.42

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 (95) hide show
  1. package/declarations/configure.d.ts +1 -1
  2. package/declarations/reactive/-private/default-mode.d.ts +1 -1
  3. package/declarations/reactive/-private/fields/extension.d.ts +1 -1
  4. package/declarations/reactive/-private/fields/managed-array.d.ts +2 -2
  5. package/declarations/reactive/-private/fields/managed-object.d.ts +1 -1
  6. package/declarations/reactive.d.ts +2 -3
  7. package/declarations/signals/-leaked.d.ts +2 -0
  8. package/declarations/signals/-private.d.ts +6 -0
  9. package/declarations/{store/-private/new-core-tmp → signals}/promise-state.d.ts +1 -1
  10. package/declarations/{store/-private/new-core-tmp → signals}/request-state.d.ts +5 -5
  11. package/declarations/{store/-private/new-core-tmp → signals}/request-subscription.d.ts +4 -4
  12. package/declarations/store/-private/cache-handler/types.d.ts +2 -16
  13. package/declarations/store/-private/managers/cache-manager.d.ts +1 -14
  14. package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +1 -1
  15. package/declarations/store/-private/record-arrays/resource-array.d.ts +1 -1
  16. package/declarations/store/-private.d.ts +0 -5
  17. package/declarations/store/deprecated/-private.d.ts +1 -1
  18. package/declarations/types/schema/fields.d.ts +4 -4
  19. package/dist/configure-DPUFCemT.js +1940 -0
  20. package/dist/configure.js +2 -1
  21. package/dist/{request-oqoLC9rz.js → future-BKkJJkj7.js} +1 -48
  22. package/dist/graph/-private.js +3 -2
  23. package/dist/{index-BKcD4JZK.js → index-CQP2NSqg.js} +58 -1826
  24. package/dist/index.js +5 -5
  25. package/dist/reactive/-private.js +1 -1
  26. package/dist/reactive.js +4 -129
  27. package/dist/request.js +49 -1
  28. package/dist/signals/-leaked.js +1 -0
  29. package/dist/store/-private.js +1 -2
  30. package/dist/types/-private.js +1 -1
  31. package/dist/unpkg/dev/-leaked-Co0EI6Go.js +1939 -0
  32. package/dist/unpkg/dev/configure.js +1 -1
  33. package/dist/unpkg/dev/{request-CA9K0gXq.js → future-DFfOzSoe.js} +1 -48
  34. package/dist/unpkg/dev/graph/-private.js +3 -2
  35. package/dist/unpkg/dev/{index-DqhXrNZ_.js → index-CepUPZlc.js} +57 -1825
  36. package/dist/unpkg/dev/index.js +4 -4
  37. package/dist/unpkg/dev/reactive/-private.js +1 -1
  38. package/dist/unpkg/dev/reactive.js +3 -127
  39. package/dist/unpkg/dev/request.js +49 -1
  40. package/dist/unpkg/dev/signals/-leaked.js +1 -0
  41. package/dist/unpkg/dev/store/-private.js +2 -3
  42. package/dist/unpkg/dev/types/-private.js +1 -1
  43. package/dist/unpkg/dev-deprecated/-leaked-DjMeRqdU.js +1939 -0
  44. package/dist/unpkg/dev-deprecated/configure.js +1 -1
  45. package/dist/unpkg/dev-deprecated/{request-CA9K0gXq.js → future-DFfOzSoe.js} +1 -48
  46. package/dist/unpkg/dev-deprecated/graph/-private.js +3 -2
  47. package/dist/unpkg/dev-deprecated/{index-BBlq5is_.js → index-C_EEmn_3.js} +56 -1824
  48. package/dist/unpkg/dev-deprecated/index.js +2 -2
  49. package/dist/unpkg/dev-deprecated/reactive.js +2 -126
  50. package/dist/unpkg/dev-deprecated/request.js +49 -1
  51. package/dist/unpkg/dev-deprecated/signals/-leaked.js +1 -0
  52. package/dist/unpkg/dev-deprecated/store/-private.js +1 -2
  53. package/dist/unpkg/dev-deprecated/types/-private.js +1 -1
  54. package/dist/unpkg/prod/-leaked-DUONXQDB.js +1676 -0
  55. package/dist/unpkg/prod/{-private-3C1OkYtZ.js → -private-sql1_mdx.js} +1 -1
  56. package/dist/unpkg/prod/configure.js +2 -1
  57. package/dist/unpkg/prod/graph/-private.js +3 -2
  58. package/dist/unpkg/prod/{handler-LAyD1Y5l.js → handler-EU_8ncB2.js} +2 -2
  59. package/dist/unpkg/prod/index.js +7 -5
  60. package/dist/unpkg/prod/promise-cache-DIT8Ypjq.js +19 -0
  61. package/dist/unpkg/prod/reactive/-private.js +1 -1
  62. package/dist/unpkg/prod/reactive.js +26 -123
  63. package/dist/unpkg/prod/{request-CN2LxbYX.js → request-BrJSCG6r.js} +3 -19
  64. package/dist/unpkg/prod/request.js +2 -1
  65. package/dist/unpkg/prod/{promise-state-ipG60SdD.js → schema-BSkHyoWz.js} +53 -1572
  66. package/dist/unpkg/prod/signals/-leaked.js +1 -0
  67. package/dist/unpkg/prod/store/-private.js +3 -4
  68. package/dist/unpkg/prod/types/-private.js +1 -1
  69. package/dist/unpkg/prod-deprecated/-leaked-DRNv9VIX.js +1676 -0
  70. package/dist/unpkg/prod-deprecated/configure.js +2 -1
  71. package/dist/unpkg/prod-deprecated/graph/-private.js +3 -2
  72. package/dist/unpkg/prod-deprecated/{handler-D639oFvl.js → handler-CCIu4sQ3.js} +1 -1
  73. package/dist/unpkg/prod-deprecated/{hooks-DGvi9teJ.js → hooks-Dv4Np0MY.js} +1 -1
  74. package/dist/unpkg/prod-deprecated/index.js +7 -5
  75. package/dist/unpkg/prod-deprecated/promise-cache-DIT8Ypjq.js +19 -0
  76. package/dist/unpkg/prod-deprecated/reactive.js +4 -125
  77. package/dist/unpkg/prod-deprecated/{request-CN2LxbYX.js → request-BrJSCG6r.js} +3 -19
  78. package/dist/unpkg/prod-deprecated/request.js +2 -1
  79. package/dist/unpkg/prod-deprecated/{promise-state-CYvoIPna.js → schema-CJcjHv0E.js} +52 -1571
  80. package/dist/unpkg/prod-deprecated/signals/-leaked.js +1 -0
  81. package/dist/unpkg/prod-deprecated/store/-private.js +2 -3
  82. package/dist/unpkg/prod-deprecated/types/-private.js +1 -1
  83. package/package.json +3 -3
  84. package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +0 -24
  85. package/dist/configure-C3x8YXzL.js +0 -181
  86. package/dist/unpkg/dev/configure-BC66sfNO.js +0 -183
  87. package/dist/unpkg/dev-deprecated/configure-BC66sfNO.js +0 -183
  88. package/dist/unpkg/prod/configure-C0C1LpG6.js +0 -158
  89. package/dist/unpkg/prod/hooks-BfiqDg3O.js +0 -26
  90. package/dist/unpkg/prod-deprecated/configure-BQ8CpIcW.js +0 -158
  91. /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/configure.d.ts +0 -0
  92. /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/internal.d.ts +0 -0
  93. /package/declarations/{store/-private/new-core-tmp → signals}/reactivity/signal.d.ts +0 -0
  94. /package/dist/{unpkg/dev/-private-3C1OkYtZ.js → symbols-3C1OkYtZ.js} +0 -0
  95. /package/dist/{symbols-sql1_mdx.js → unpkg/dev/-private-sql1_mdx.js} +0 -0
@@ -0,0 +1 @@
1
+ export { D as DISPOSE, d as defineGate, o as defineNonEnumerableSignal, j as defineSignal, k as entangleSignal, t as gate, u as memoized, n as notifyInternalSignal, p as peekInternalSignal, q as signal, r as waitFor, w as withSignalStore } from "../-leaked-DRNv9VIX.js";
@@ -1,6 +1,5 @@
1
- export { D as DISPOSE, R as RecordArrayManager, z as Signals, S as Store, k as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, h as assertPrivateCapabilities, d as assertPrivateStore, b as coerceId, c as constructResource, F as consumeInternalSignal, B as createInternalMemo, l as createLegacyManyArray, m as createRequestSubscription, x as defineGate, y as defineNonEnumerableSignal, w as defineSignal, e as ensureStringId, v as entangleInitiallyStaleSignal, u as entangleSignal, f as fastPush, t as gate, G as getOrCreateInternalSignal, o as getRequestState, g as isPrivateStore, a as isRequestKey, i as isResourceKey, q as memoized, E as notifyInternalSignal, A as peekInternalSignal, r as recordIdentifierFor, j as setRecordIdentifier, p as signal, s as storeFor, C as withSignalStore } from "../promise-state-CYvoIPna.js";
2
- export { C as CacheHandler } from "../handler-D639oFvl.js";
3
- export { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, w as waitFor } from "../configure-BQ8CpIcW.js";
1
+ export { R as RecordArrayManager, b as Store, p as StoreMap, _ as _clearCaches, q as _deprecatingNormalize, n as assertPrivateCapabilities, l as assertPrivateStore, h as coerceId, g as constructResource, t as createLegacyManyArray, j as ensureStringId, k as fastPush, m as isPrivateStore, e as isRequestKey, i as isResourceKey, d as recordIdentifierFor, o as setRecordIdentifier, s as storeFor } from "../schema-CJcjHv0E.js";
2
+ export { C as CacheHandler } from "../handler-CCIu4sQ3.js";
4
3
  const TEXT_COLORS = {
5
4
  TEXT: 'inherit',
6
5
  notify: ['white', 'white', 'inherit', 'magenta', 'inherit'],
@@ -1,5 +1,5 @@
1
1
  const name = "@warp-drive/core";
2
- const version = "5.8.0-alpha.40";
2
+ const version = "5.8.0-alpha.42";
3
3
 
4
4
  // in testing mode, we utilize globals to ensure only one copy exists of
5
5
  // these maps, due to bugs in ember-auto-import
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warp-drive/core",
3
- "version": "5.8.0-alpha.40",
3
+ "version": "5.8.0-alpha.42",
4
4
  "description": "Core package for WarpDrive | All the Universal Basics",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -45,13 +45,13 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@embroider/macros": "^1.18.1",
48
- "@warp-drive/build-config": "5.8.0-alpha.40"
48
+ "@warp-drive/build-config": "5.8.0-alpha.42"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@babel/core": "^7.28.3",
52
52
  "@babel/plugin-transform-typescript": "^7.28.0",
53
53
  "@babel/preset-typescript": "^7.27.1",
54
- "@warp-drive/internal-config": "5.8.0-alpha.40",
54
+ "@warp-drive/internal-config": "5.8.0-alpha.42",
55
55
  "decorator-transforms": "^2.3.0",
56
56
  "ember-source": "~6.6.0",
57
57
  "expect-type": "^1.2.2",
@@ -1,24 +0,0 @@
1
- import type { RequestKey } from "../../../types/identifier.js";
2
- import type { Store } from "../store-service.js";
3
- /**
4
- * Creates an {@link ExpensiveSubscription} for the {@link RequestKey}
5
- * if one does not already exist and adds a watcher to it.
6
- *
7
- * Returns a cleanup function. This should be called on-mount by a component
8
- * that wants to subscribe to a request and cleanup should be called on dismount.
9
- *
10
- * ::: warning ⚠️ Avoid Using If Your App Supports Fine-grained Reactivity
11
- * This mechanism should never be used by frameworks or libraries
12
- * that support fine-grained reactivity.
13
- * :::
14
- *
15
- * `ExpensiveSubscription` is a mechanism for non-reactive
16
- * frameworks such as `react` to integrate with WarpDrive, for instance
17
- * by treating a request as an [external store](https://react.dev/reference/react/useSyncExternalStore)
18
- *
19
- * `ExpensiveSubscription` is expensive *because* it doubles the number
20
- * of notification callbacks required for each resource contained in
21
- * the request being subscribed to. The more requests in-use, the more
22
- * this cost adds up.
23
- */
24
- export declare function getExpensiveRequestSubscription(store: Store, requestKey: RequestKey, callback: () => void): () => void;
@@ -1,181 +0,0 @@
1
- import { getOrSetGlobal, peekTransient, setTransient } from './types/-private.js';
2
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
3
- const ARRAY_SIGNAL = getOrSetGlobal('#[]', Symbol('#[]'));
4
- const OBJECT_SIGNAL = getOrSetGlobal('#{}', Symbol('#{}'));
5
-
6
- /**
7
- * Requirements:
8
- *
9
- * Signal:
10
- *
11
- * - signal: a way of creating a reference that we can dirty when we desire to notify
12
- * - @signal: a way of creating an accessor on an object that subscribes to a signal on access
13
- * and notifies the signal on set, or of upgrading a descriptor to be such an accessor
14
- * - defineSignal: a way of creating a signal on an object
15
- * - notifySignal: a way of notifying the underlying signal that it has been dirtied
16
- * - peekSignal: a way of inspecting the signal without notifying it
17
- *
18
- * - gate: a memoized getter function that re-runs when on access if its signal is dirty
19
- * conceptually, a gate is a tightly coupled signal and memo
20
- * - @gate: a way of creating a gate on an object or upgrading a descriptor with a getter
21
- * to be a gate
22
- * - defineGate: a way of creating a gate on an object
23
- * - notifySignal: a way of notifying the signal for a gate that it has been dirtied
24
- *
25
- * - memo:
26
- * - @memo: a way of creating a memoized getter on an object or upgrading a descriptor with a getter
27
- * to be a memo
28
- * - defineMemo: a way of creating a memo on an object
29
- *
30
- * - signalStore: storage bucket for signals associated to an object
31
- * - withSignalStore: a way of pre-creating a signal store on an object
32
- *
33
- *
34
- * @internal
35
- */
36
-
37
- /**
38
- * An Opaque type that represents a framework specific or TC39 signal.
39
- *
40
- * It may be an array of signals or a single signal.
41
- *
42
- * @private
43
- */
44
-
45
- /**
46
- * The hooks which MUST be configured in order to use reactive arrays,
47
- * resources and documents with framework specfic signals or TC39 signals.
48
- *
49
- * Support for multiple frameworks simultaneously can be done via
50
- * this abstraction by returning multiple signals from the `createSignal`
51
- * method, and consuming the correct one via the correct framework via
52
- * the `consumeSignal` and `notifySignal` methods.
53
- *
54
- * Unlike many signals implementations, WarpDrive does not wrap values as
55
- * signals directly, but instead uses signals to alert the reactive layer
56
- * to changes in the underlying cache. E.g. a signal is associated to a value,
57
- * but does not serve as the cache for that value directly. We refer to this as
58
- * a "gate", the pattern has also been called "side-signals".
59
- *
60
- * A no-op implementation is allowed, though it may lead to performance issues
61
- * in locations that use createMemo as no memoization would be done. This is
62
- * typically desirable only when integrating with a framework that does its own
63
- * memoization and does not integrate with any signals-like primitive. For these
64
- * scenarios you may also be interested in integrating with the {@link NotificationManager}
65
- * more directly.
66
- *
67
- * @public
68
- */
69
-
70
- /**
71
- * Contains information a {@link SignalHooks} implementation may want
72
- * to use, such as the specialized key used for the signal
73
- * representing an array's contents / length.
74
- *
75
- * ```ts
76
- * interface HooksOptions {
77
- * wellknown: {
78
- * Array: symbol | string;
79
- * }
80
- * }
81
- * ```
82
- *
83
- * @public
84
- */
85
-
86
- /**
87
- * Configures the signals implementation to use. Supports multiple
88
- * implementations simultaneously.
89
- *
90
- * See {@link HooksOptions} for the options passed to the provided function
91
- * when called.
92
- *
93
- * See {@link SignalHooks} for the implementation the callback function should
94
- * return.
95
- *
96
- * @public
97
- * @param buildConfig - a function that takes options and returns a configuration object
98
- */
99
- function setupSignals(buildConfig) {
100
- // We want to assert this but can't because too many package manager
101
- // and bundler bugs exist that cause this to be called multiple times
102
- // for what should be a single call.
103
- // assert(`Cannot override configured signal hooks`, peekTransient('signalHooks') === null);
104
- const hooks = buildConfig({
105
- wellknown: {
106
- Array: ARRAY_SIGNAL
107
- }
108
- });
109
- setTransient('signalHooks', hooks);
110
- }
111
-
112
- /**
113
- * Internal method for consuming the configured `createSignal` hook
114
- *
115
- * @private
116
- */
117
- function createSignal(obj, key) {
118
- const signalHooks = peekTransient('signalHooks');
119
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
120
- if (!test) {
121
- throw new Error(`Signal hooks not configured`);
122
- }
123
- })(signalHooks) : {};
124
- return signalHooks.createSignal(obj, key);
125
- }
126
-
127
- /**
128
- * Internal method for consuming the configured `consumeSignal` hook
129
- *
130
- * @private
131
- */
132
- function consumeSignal(signal) {
133
- const signalHooks = peekTransient('signalHooks');
134
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
135
- if (!test) {
136
- throw new Error(`Signal hooks not configured`);
137
- }
138
- })(signalHooks) : {};
139
- return signalHooks.consumeSignal(signal);
140
- }
141
-
142
- /**
143
- * Internal method for consuming the configured `notifySignal` hook
144
- *
145
- * @private
146
- */
147
- function notifySignal(signal) {
148
- const signalHooks = peekTransient('signalHooks');
149
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
150
- if (!test) {
151
- throw new Error(`Signal hooks not configured`);
152
- }
153
- })(signalHooks) : {};
154
- return signalHooks.notifySignal(signal);
155
- }
156
- function createMemo(object, key, fn) {
157
- const signalHooks = peekTransient('signalHooks');
158
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
159
- if (!test) {
160
- throw new Error(`Signal hooks not configured`);
161
- }
162
- })(signalHooks) : {};
163
- return signalHooks.createMemo(object, key, fn);
164
- }
165
- function willSyncFlushWatchers() {
166
- const signalHooks = peekTransient('signalHooks');
167
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
168
- if (!test) {
169
- throw new Error(`Signal hooks not configured`);
170
- }
171
- })(signalHooks) : {};
172
- return signalHooks.willSyncFlushWatchers();
173
- }
174
- function waitFor(promise) {
175
- const signalHooks = peekTransient('signalHooks');
176
- if (signalHooks?.waitFor) {
177
- return signalHooks.waitFor(promise);
178
- }
179
- return promise;
180
- }
181
- export { ARRAY_SIGNAL as A, OBJECT_SIGNAL as O, consumeSignal as a, createMemo as b, createSignal as c, willSyncFlushWatchers as d, notifySignal as n, setupSignals as s, waitFor as w };
@@ -1,183 +0,0 @@
1
- import { getOrSetGlobal, peekTransient, setTransient } from './types/-private.js';
2
-
3
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
-
5
- const ARRAY_SIGNAL = getOrSetGlobal('#[]', Symbol('#[]'));
6
- const OBJECT_SIGNAL = getOrSetGlobal('#{}', Symbol('#{}'));
7
-
8
- /**
9
- * Requirements:
10
- *
11
- * Signal:
12
- *
13
- * - signal: a way of creating a reference that we can dirty when we desire to notify
14
- * - @signal: a way of creating an accessor on an object that subscribes to a signal on access
15
- * and notifies the signal on set, or of upgrading a descriptor to be such an accessor
16
- * - defineSignal: a way of creating a signal on an object
17
- * - notifySignal: a way of notifying the underlying signal that it has been dirtied
18
- * - peekSignal: a way of inspecting the signal without notifying it
19
- *
20
- * - gate: a memoized getter function that re-runs when on access if its signal is dirty
21
- * conceptually, a gate is a tightly coupled signal and memo
22
- * - @gate: a way of creating a gate on an object or upgrading a descriptor with a getter
23
- * to be a gate
24
- * - defineGate: a way of creating a gate on an object
25
- * - notifySignal: a way of notifying the signal for a gate that it has been dirtied
26
- *
27
- * - memo:
28
- * - @memo: a way of creating a memoized getter on an object or upgrading a descriptor with a getter
29
- * to be a memo
30
- * - defineMemo: a way of creating a memo on an object
31
- *
32
- * - signalStore: storage bucket for signals associated to an object
33
- * - withSignalStore: a way of pre-creating a signal store on an object
34
- *
35
- *
36
- * @internal
37
- */
38
-
39
- /**
40
- * An Opaque type that represents a framework specific or TC39 signal.
41
- *
42
- * It may be an array of signals or a single signal.
43
- *
44
- * @private
45
- */
46
-
47
- /**
48
- * The hooks which MUST be configured in order to use reactive arrays,
49
- * resources and documents with framework specfic signals or TC39 signals.
50
- *
51
- * Support for multiple frameworks simultaneously can be done via
52
- * this abstraction by returning multiple signals from the `createSignal`
53
- * method, and consuming the correct one via the correct framework via
54
- * the `consumeSignal` and `notifySignal` methods.
55
- *
56
- * Unlike many signals implementations, WarpDrive does not wrap values as
57
- * signals directly, but instead uses signals to alert the reactive layer
58
- * to changes in the underlying cache. E.g. a signal is associated to a value,
59
- * but does not serve as the cache for that value directly. We refer to this as
60
- * a "gate", the pattern has also been called "side-signals".
61
- *
62
- * A no-op implementation is allowed, though it may lead to performance issues
63
- * in locations that use createMemo as no memoization would be done. This is
64
- * typically desirable only when integrating with a framework that does its own
65
- * memoization and does not integrate with any signals-like primitive. For these
66
- * scenarios you may also be interested in integrating with the {@link NotificationManager}
67
- * more directly.
68
- *
69
- * @public
70
- */
71
-
72
- /**
73
- * Contains information a {@link SignalHooks} implementation may want
74
- * to use, such as the specialized key used for the signal
75
- * representing an array's contents / length.
76
- *
77
- * ```ts
78
- * interface HooksOptions {
79
- * wellknown: {
80
- * Array: symbol | string;
81
- * }
82
- * }
83
- * ```
84
- *
85
- * @public
86
- */
87
-
88
- /**
89
- * Configures the signals implementation to use. Supports multiple
90
- * implementations simultaneously.
91
- *
92
- * See {@link HooksOptions} for the options passed to the provided function
93
- * when called.
94
- *
95
- * See {@link SignalHooks} for the implementation the callback function should
96
- * return.
97
- *
98
- * @public
99
- * @param buildConfig - a function that takes options and returns a configuration object
100
- */
101
- function setupSignals(buildConfig) {
102
- // We want to assert this but can't because too many package manager
103
- // and bundler bugs exist that cause this to be called multiple times
104
- // for what should be a single call.
105
- // assert(`Cannot override configured signal hooks`, peekTransient('signalHooks') === null);
106
- const hooks = buildConfig({
107
- wellknown: {
108
- Array: ARRAY_SIGNAL
109
- }
110
- });
111
- setTransient('signalHooks', hooks);
112
- }
113
-
114
- /**
115
- * Internal method for consuming the configured `createSignal` hook
116
- *
117
- * @private
118
- */
119
- function createSignal(obj, key) {
120
- const signalHooks = peekTransient('signalHooks');
121
- (test => {
122
- if (!test) {
123
- throw new Error(`Signal hooks not configured`);
124
- }
125
- })(signalHooks);
126
- return signalHooks.createSignal(obj, key);
127
- }
128
-
129
- /**
130
- * Internal method for consuming the configured `consumeSignal` hook
131
- *
132
- * @private
133
- */
134
- function consumeSignal(signal) {
135
- const signalHooks = peekTransient('signalHooks');
136
- (test => {
137
- if (!test) {
138
- throw new Error(`Signal hooks not configured`);
139
- }
140
- })(signalHooks);
141
- return signalHooks.consumeSignal(signal);
142
- }
143
-
144
- /**
145
- * Internal method for consuming the configured `notifySignal` hook
146
- *
147
- * @private
148
- */
149
- function notifySignal(signal) {
150
- const signalHooks = peekTransient('signalHooks');
151
- (test => {
152
- if (!test) {
153
- throw new Error(`Signal hooks not configured`);
154
- }
155
- })(signalHooks);
156
- return signalHooks.notifySignal(signal);
157
- }
158
- function createMemo(object, key, fn) {
159
- const signalHooks = peekTransient('signalHooks');
160
- (test => {
161
- if (!test) {
162
- throw new Error(`Signal hooks not configured`);
163
- }
164
- })(signalHooks);
165
- return signalHooks.createMemo(object, key, fn);
166
- }
167
- function willSyncFlushWatchers() {
168
- const signalHooks = peekTransient('signalHooks');
169
- (test => {
170
- if (!test) {
171
- throw new Error(`Signal hooks not configured`);
172
- }
173
- })(signalHooks);
174
- return signalHooks.willSyncFlushWatchers();
175
- }
176
- function waitFor(promise) {
177
- const signalHooks = peekTransient('signalHooks');
178
- if (signalHooks?.waitFor) {
179
- return signalHooks.waitFor(promise);
180
- }
181
- return promise;
182
- }
183
- export { ARRAY_SIGNAL as A, OBJECT_SIGNAL as O, consumeSignal as a, createMemo as b, createSignal as c, willSyncFlushWatchers as d, notifySignal as n, setupSignals as s, waitFor as w };
@@ -1,183 +0,0 @@
1
- import { getOrSetGlobal, peekTransient, setTransient } from './types/-private.js';
2
-
3
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
-
5
- const ARRAY_SIGNAL = getOrSetGlobal('#[]', Symbol('#[]'));
6
- const OBJECT_SIGNAL = getOrSetGlobal('#{}', Symbol('#{}'));
7
-
8
- /**
9
- * Requirements:
10
- *
11
- * Signal:
12
- *
13
- * - signal: a way of creating a reference that we can dirty when we desire to notify
14
- * - @signal: a way of creating an accessor on an object that subscribes to a signal on access
15
- * and notifies the signal on set, or of upgrading a descriptor to be such an accessor
16
- * - defineSignal: a way of creating a signal on an object
17
- * - notifySignal: a way of notifying the underlying signal that it has been dirtied
18
- * - peekSignal: a way of inspecting the signal without notifying it
19
- *
20
- * - gate: a memoized getter function that re-runs when on access if its signal is dirty
21
- * conceptually, a gate is a tightly coupled signal and memo
22
- * - @gate: a way of creating a gate on an object or upgrading a descriptor with a getter
23
- * to be a gate
24
- * - defineGate: a way of creating a gate on an object
25
- * - notifySignal: a way of notifying the signal for a gate that it has been dirtied
26
- *
27
- * - memo:
28
- * - @memo: a way of creating a memoized getter on an object or upgrading a descriptor with a getter
29
- * to be a memo
30
- * - defineMemo: a way of creating a memo on an object
31
- *
32
- * - signalStore: storage bucket for signals associated to an object
33
- * - withSignalStore: a way of pre-creating a signal store on an object
34
- *
35
- *
36
- * @internal
37
- */
38
-
39
- /**
40
- * An Opaque type that represents a framework specific or TC39 signal.
41
- *
42
- * It may be an array of signals or a single signal.
43
- *
44
- * @private
45
- */
46
-
47
- /**
48
- * The hooks which MUST be configured in order to use reactive arrays,
49
- * resources and documents with framework specfic signals or TC39 signals.
50
- *
51
- * Support for multiple frameworks simultaneously can be done via
52
- * this abstraction by returning multiple signals from the `createSignal`
53
- * method, and consuming the correct one via the correct framework via
54
- * the `consumeSignal` and `notifySignal` methods.
55
- *
56
- * Unlike many signals implementations, WarpDrive does not wrap values as
57
- * signals directly, but instead uses signals to alert the reactive layer
58
- * to changes in the underlying cache. E.g. a signal is associated to a value,
59
- * but does not serve as the cache for that value directly. We refer to this as
60
- * a "gate", the pattern has also been called "side-signals".
61
- *
62
- * A no-op implementation is allowed, though it may lead to performance issues
63
- * in locations that use createMemo as no memoization would be done. This is
64
- * typically desirable only when integrating with a framework that does its own
65
- * memoization and does not integrate with any signals-like primitive. For these
66
- * scenarios you may also be interested in integrating with the {@link NotificationManager}
67
- * more directly.
68
- *
69
- * @public
70
- */
71
-
72
- /**
73
- * Contains information a {@link SignalHooks} implementation may want
74
- * to use, such as the specialized key used for the signal
75
- * representing an array's contents / length.
76
- *
77
- * ```ts
78
- * interface HooksOptions {
79
- * wellknown: {
80
- * Array: symbol | string;
81
- * }
82
- * }
83
- * ```
84
- *
85
- * @public
86
- */
87
-
88
- /**
89
- * Configures the signals implementation to use. Supports multiple
90
- * implementations simultaneously.
91
- *
92
- * See {@link HooksOptions} for the options passed to the provided function
93
- * when called.
94
- *
95
- * See {@link SignalHooks} for the implementation the callback function should
96
- * return.
97
- *
98
- * @public
99
- * @param buildConfig - a function that takes options and returns a configuration object
100
- */
101
- function setupSignals(buildConfig) {
102
- // We want to assert this but can't because too many package manager
103
- // and bundler bugs exist that cause this to be called multiple times
104
- // for what should be a single call.
105
- // assert(`Cannot override configured signal hooks`, peekTransient('signalHooks') === null);
106
- const hooks = buildConfig({
107
- wellknown: {
108
- Array: ARRAY_SIGNAL
109
- }
110
- });
111
- setTransient('signalHooks', hooks);
112
- }
113
-
114
- /**
115
- * Internal method for consuming the configured `createSignal` hook
116
- *
117
- * @private
118
- */
119
- function createSignal(obj, key) {
120
- const signalHooks = peekTransient('signalHooks');
121
- (test => {
122
- if (!test) {
123
- throw new Error(`Signal hooks not configured`);
124
- }
125
- })(signalHooks);
126
- return signalHooks.createSignal(obj, key);
127
- }
128
-
129
- /**
130
- * Internal method for consuming the configured `consumeSignal` hook
131
- *
132
- * @private
133
- */
134
- function consumeSignal(signal) {
135
- const signalHooks = peekTransient('signalHooks');
136
- (test => {
137
- if (!test) {
138
- throw new Error(`Signal hooks not configured`);
139
- }
140
- })(signalHooks);
141
- return signalHooks.consumeSignal(signal);
142
- }
143
-
144
- /**
145
- * Internal method for consuming the configured `notifySignal` hook
146
- *
147
- * @private
148
- */
149
- function notifySignal(signal) {
150
- const signalHooks = peekTransient('signalHooks');
151
- (test => {
152
- if (!test) {
153
- throw new Error(`Signal hooks not configured`);
154
- }
155
- })(signalHooks);
156
- return signalHooks.notifySignal(signal);
157
- }
158
- function createMemo(object, key, fn) {
159
- const signalHooks = peekTransient('signalHooks');
160
- (test => {
161
- if (!test) {
162
- throw new Error(`Signal hooks not configured`);
163
- }
164
- })(signalHooks);
165
- return signalHooks.createMemo(object, key, fn);
166
- }
167
- function willSyncFlushWatchers() {
168
- const signalHooks = peekTransient('signalHooks');
169
- (test => {
170
- if (!test) {
171
- throw new Error(`Signal hooks not configured`);
172
- }
173
- })(signalHooks);
174
- return signalHooks.willSyncFlushWatchers();
175
- }
176
- function waitFor(promise) {
177
- const signalHooks = peekTransient('signalHooks');
178
- if (signalHooks?.waitFor) {
179
- return signalHooks.waitFor(promise);
180
- }
181
- return promise;
182
- }
183
- export { ARRAY_SIGNAL as A, OBJECT_SIGNAL as O, consumeSignal as a, createMemo as b, createSignal as c, willSyncFlushWatchers as d, notifySignal as n, setupSignals as s, waitFor as w };