@solidjs/signals 2.0.0-rc.7 → 2.0.0-rc.8
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.
- package/dist/dev-shared.js +5243 -0
- package/dist/dev.attribution.js +2333 -0
- package/dist/dev.js +1229 -6834
- package/dist/observe/affects.js +127 -0
- package/dist/observe/attribution.js +1 -0
- package/dist/observe/boundaries.js +586 -0
- package/dist/observe/core/action.js +167 -0
- package/dist/observe/core/async.js +736 -0
- package/dist/observe/core/attribution-hooks.js +60 -0
- package/dist/observe/core/attribution.js +2318 -0
- package/dist/{types-cjs/core/constants.d.cts → observe/core/constants.js} +129 -73
- package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
- package/dist/observe/core/core.js +1289 -0
- package/dist/observe/core/dev.js +232 -0
- package/dist/observe/core/effect.js +179 -0
- package/dist/observe/core/error.js +80 -0
- package/dist/observe/core/external.js +98 -0
- package/dist/observe/core/graph.js +155 -0
- package/dist/observe/core/heap.js +147 -0
- package/dist/observe/core/invariants.js +43 -0
- package/dist/observe/core/lanes.js +168 -0
- package/dist/observe/core/optimistic.js +438 -0
- package/dist/observe/core/owner.js +308 -0
- package/dist/observe/core/scheduler.js +1190 -0
- package/dist/observe/core/verdict.js +551 -0
- package/dist/observe/index.js +55 -0
- package/dist/observe/map.js +482 -0
- package/dist/{types-cjs/signals.d.cts → observe/signals.js} +295 -317
- package/dist/observe/store/index.js +38 -0
- package/dist/observe/store/next/optimistic.js +651 -0
- package/dist/observe/store/next/projection.js +242 -0
- package/dist/observe/store/next/reconcile.js +373 -0
- package/dist/observe/store/next/store.js +2213 -0
- package/dist/observe/store/next/target.js +51 -0
- package/dist/observe/store/store.js +323 -0
- package/dist/observe/store/storePath.js +103 -0
- package/dist/observe/store/utils.js +210 -0
- package/dist/prod/attribution.js +32 -0
- package/dist/prod/core/action.js +52 -32
- package/dist/prod/core/async.js +171 -127
- package/dist/prod/core/constants.js +24 -1
- package/dist/prod/core/context.js +3 -3
- package/dist/prod/core/core.js +434 -291
- package/dist/prod/core/effect.js +54 -34
- package/dist/prod/core/external.js +2 -2
- package/dist/prod/core/graph.js +32 -32
- package/dist/prod/core/heap.js +49 -44
- package/dist/prod/core/lanes.js +45 -38
- package/dist/prod/core/optimistic.js +207 -73
- package/dist/prod/core/owner.js +43 -39
- package/dist/prod/core/scheduler.js +319 -190
- package/dist/prod/core/verdict.js +67 -67
- package/dist/prod/index.js +9 -3
- package/dist/prod/map.js +292 -141
- package/dist/prod/signals.js +7 -10
- package/dist/prod/store/next/optimistic.js +140 -125
- package/dist/prod/store/next/projection.js +3 -3
- package/dist/prod/store/next/reconcile.js +87 -84
- package/dist/prod/store/next/store.js +524 -280
- package/dist/prod/store/next/target.js +32 -10
- package/dist/prod/store/store.js +12 -14
- package/dist/prod/store/utils.js +36 -27
- package/dist/types/attribution.d.ts +15 -0
- package/dist/types/attribution.prod.d.ts +13 -0
- package/dist/types/core/async.d.ts +1 -1
- package/dist/types/core/attribution-hooks.d.ts +119 -6
- package/dist/types/core/attribution.d.ts +208 -53
- package/dist/types/core/constants.d.ts +23 -0
- package/dist/types/core/core.d.ts +7 -0
- package/dist/types/core/dev.d.ts +124 -26
- package/dist/types/core/effect.d.ts +8 -1
- package/dist/types/core/index.d.ts +2 -1
- package/dist/types/core/lanes.d.ts +8 -1
- package/dist/types/core/scheduler.d.ts +60 -0
- package/dist/types/core/types.d.ts +29 -9
- package/dist/types/index.d.ts +9 -2
- package/dist/types/map.d.ts +2 -0
- package/dist/types/store/index.d.ts +1 -0
- package/dist/types/store/next/store.d.ts +5 -0
- package/dist/types/store/next/target.d.ts +36 -9
- package/dist/types/store/utils.d.ts +7 -0
- package/package.json +21 -17
- package/dist/node.cjs +0 -10541
- package/dist/node.dev.cjs +0 -13724
- package/dist/types-cjs/affects.d.cts +0 -47
- package/dist/types-cjs/boundaries.d.cts +0 -175
- package/dist/types-cjs/core/action.d.cts +0 -64
- package/dist/types-cjs/core/async.d.cts +0 -23
- package/dist/types-cjs/core/attribution-hooks.d.cts +0 -127
- package/dist/types-cjs/core/attribution.d.cts +0 -495
- package/dist/types-cjs/core/core.d.cts +0 -185
- package/dist/types-cjs/core/dev.d.cts +0 -136
- package/dist/types-cjs/core/effect.d.cts +0 -30
- package/dist/types-cjs/core/error.d.cts +0 -56
- package/dist/types-cjs/core/external.d.cts +0 -15
- package/dist/types-cjs/core/graph.d.cts +0 -28
- package/dist/types-cjs/core/heap.d.cts +0 -24
- package/dist/types-cjs/core/index.d.cts +0 -13
- package/dist/types-cjs/core/invariants.d.cts +0 -59
- package/dist/types-cjs/core/lanes.d.cts +0 -54
- package/dist/types-cjs/core/optimistic.d.cts +0 -6
- package/dist/types-cjs/core/owner.d.cts +0 -124
- package/dist/types-cjs/core/scheduler.d.cts +0 -236
- package/dist/types-cjs/core/types.d.cts +0 -204
- package/dist/types-cjs/core/verdict.d.cts +0 -2
- package/dist/types-cjs/index.d.cts +0 -10
- package/dist/types-cjs/map.d.cts +0 -69
- package/dist/types-cjs/package.json +0 -3
- package/dist/types-cjs/store/index.d.cts +0 -18
- package/dist/types-cjs/store/next/optimistic.d.cts +0 -25
- package/dist/types-cjs/store/next/projection.d.cts +0 -8
- package/dist/types-cjs/store/next/reconcile.d.cts +0 -10
- package/dist/types-cjs/store/next/store.d.cts +0 -121
- package/dist/types-cjs/store/next/target.d.cts +0 -166
- package/dist/types-cjs/store/store.d.cts +0 -143
- package/dist/types-cjs/store/storePath.d.cts +0 -58
- package/dist/types-cjs/store/utils.d.cts +0 -74
|
@@ -1,23 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
const REACTIVE_NONE = 0;
|
|
2
|
+
|
|
3
|
+
const REACTIVE_CHECK = 1 << 0;
|
|
4
|
+
|
|
5
|
+
const REACTIVE_DIRTY = 1 << 1;
|
|
6
|
+
|
|
7
|
+
const REACTIVE_RECOMPUTING_DEPS = 1 << 2;
|
|
8
|
+
|
|
9
|
+
const REACTIVE_IN_HEAP = 1 << 3;
|
|
10
|
+
|
|
11
|
+
const REACTIVE_IN_HEAP_HEIGHT = 1 << 4;
|
|
12
|
+
|
|
13
|
+
const REACTIVE_ZOMBIE = 1 << 5;
|
|
14
|
+
|
|
15
|
+
const REACTIVE_DISPOSED = 1 << 6;
|
|
16
|
+
|
|
17
|
+
const REACTIVE_OPTIMISTIC_DIRTY = 1 << 7;
|
|
18
|
+
|
|
19
|
+
const REACTIVE_SNAPSHOT_STALE = 1 << 8;
|
|
20
|
+
|
|
21
|
+
const REACTIVE_LAZY = 1 << 9;
|
|
22
|
+
|
|
23
|
+
const REACTIVE_MANUAL_WRITE = 1 << 10;
|
|
24
|
+
|
|
13
25
|
/**
|
|
14
26
|
* The pending recompute is a re-ask of the same question: `refresh()` dirtied
|
|
15
27
|
* the node while no tracked input changed value. Cleared whenever a real
|
|
16
28
|
* value-change notification arrives (`insertSubs`), and consumed by
|
|
17
29
|
* `recompute` into the node's `_reask` classification — a quiet (re-ask)
|
|
18
30
|
* pending window does not read as pending (question-scoped pending model).
|
|
19
|
-
*/
|
|
20
|
-
|
|
31
|
+
*/ const REACTIVE_REASK = 1 << 11;
|
|
32
|
+
|
|
21
33
|
/**
|
|
22
34
|
* A dependency write landed while this subscriber was mid-recompute — a
|
|
23
35
|
* nested pull committed beneath one of its reads (#3037). The heap refuses
|
|
@@ -25,32 +37,52 @@ export declare const REACTIVE_REASK: number;
|
|
|
25
37
|
* values the pass read before the nested commit are stale. Only set for
|
|
26
38
|
* links validated this pass (gen-current): a write to an untouched link is
|
|
27
39
|
* either re-read later in the pass (fresh) or trimmed with it (not a dep).
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
*/ const REACTIVE_MISSED_WAKE = 1 << 12;
|
|
41
|
+
|
|
42
|
+
// Static configuration bits packed into Owner/Computed/Signal _config.
|
|
43
|
+
const CONFIG_OWNED_WRITE = 1 << 0;
|
|
44
|
+
|
|
45
|
+
const CONFIG_NO_SNAPSHOT = 1 << 1;
|
|
46
|
+
|
|
47
|
+
const CONFIG_TRANSPARENT = 1 << 2;
|
|
48
|
+
|
|
49
|
+
const CONFIG_IN_SNAPSHOT_SCOPE = 1 << 3;
|
|
50
|
+
|
|
51
|
+
const CONFIG_CHILDREN_FORBIDDEN = 1 << 4;
|
|
52
|
+
|
|
53
|
+
const CONFIG_AUTO_DISPOSE = 1 << 5;
|
|
54
|
+
|
|
55
|
+
const CONFIG_SYNC = 1 << 6;
|
|
56
|
+
|
|
57
|
+
// Presence bits (stage-3 hot-path monomorphism, DESIGN-PATCH-CHANNEL §11b):
|
|
58
|
+
// optional per-node slots (_overrideValue, _pendingSignal/_latestValueComputed,
|
|
59
|
+
// _snapshotValue, _optimisticLane) are NOT part of every node's hidden class —
|
|
60
|
+
// reading a missing property defeats V8's inline caches on the hottest write/
|
|
61
|
+
// notify loops. These bits live on the always-present `_config` so hot paths
|
|
62
|
+
// pay one monomorphic masked read and only touch the optional field when its
|
|
63
|
+
// installer flagged it. Bits are STICKY ("may be set") — the guarded field
|
|
64
|
+
// read remains authoritative.
|
|
65
|
+
const CONFIG_OPTIMISTIC = 1 << 7;
|
|
66
|
+
|
|
67
|
+
const CONFIG_HAS_COMPANIONS = 1 << 8;
|
|
68
|
+
|
|
69
|
+
const CONFIG_HAS_SNAPSHOT = 1 << 9;
|
|
70
|
+
|
|
71
|
+
const CONFIG_HAS_LANE = 1 << 10;
|
|
72
|
+
|
|
41
73
|
/** Set on a FIREWALL computed when any of its child signals creates an
|
|
42
74
|
* isPending()/latest() companion. Gates the post-recompute child-companion
|
|
43
75
|
* walk (#3038): a store computed's `_child` chain holds one node per
|
|
44
76
|
* materialized leaf, so walking it unconditionally makes every update cost
|
|
45
77
|
* O(all leaves ever read). Sticky — set at companion creation, never
|
|
46
|
-
* cleared; sync-only apps never set it and never pay the walk. */
|
|
47
|
-
|
|
78
|
+
* cleared; sync-only apps never set it and never pay the walk. */ const CONFIG_CHILD_COMPANIONS = 1 << 11;
|
|
79
|
+
|
|
48
80
|
/** Set on a computed when its first firewall child signal is installed
|
|
49
81
|
* (projection machinery). Gates markNode's firewall-children walk with one
|
|
50
82
|
* masked read of the always-present _config — the walk's old `_child` read
|
|
51
83
|
* moved into the cold extension (§12), and an unconditional `_x` deref per
|
|
52
|
-
* marked node measurably taxed the propagation hot path (diamond -22%). */
|
|
53
|
-
|
|
84
|
+
* marked node measurably taxed the propagation hot path (diamond -22%). */ const CONFIG_FW_CHILDREN = 1 << 12;
|
|
85
|
+
|
|
54
86
|
/** Authoritative-view reader (`until()`): while this node computes, reads
|
|
55
87
|
* dodge active optimistic OVERRIDES only — the predicate must observe
|
|
56
88
|
* arriving truth, never the caller's own tentative writes (which would
|
|
@@ -61,24 +93,24 @@ export declare const CONFIG_FW_CHILDREN: number;
|
|
|
61
93
|
* action issued lands staged and cannot commit until the hold releases).
|
|
62
94
|
* read() checks the bit on the reading computation (`context`) directly — no
|
|
63
95
|
* ambient flag — so a shared computed the predicate pulls recomputes as
|
|
64
|
-
* itself (no bit) under the normal view, and its cache never forks. */
|
|
65
|
-
|
|
96
|
+
* itself (no bit) under the normal view, and its cache never forks. */ const CONFIG_AUTHORITATIVE_READ = 1 << 13;
|
|
97
|
+
|
|
66
98
|
/** Sticky mark: an authoritative-view reader read this node PAST an active
|
|
67
99
|
* override. The ack shape — an authoritative arrival EQUAL to the override —
|
|
68
100
|
* rides paths that are deliberately silent under A17 (every ordinary reader
|
|
69
101
|
* sees the override, so an equal landing changes nothing for them). A marked
|
|
70
102
|
* node notifies those readers on such paths anyway, so the landed truth is
|
|
71
103
|
* seen without re-firing ordinary subscribers. Never cleared — only nodes an
|
|
72
|
-
* until() predicate observed mid-override pay. */
|
|
73
|
-
|
|
104
|
+
* until() predicate observed mid-override pay. */ const CONFIG_AUTHORITATIVE_OBSERVED = 1 << 14;
|
|
105
|
+
|
|
74
106
|
/** Promise-delivery effect (resolve()/until()): commits its computed value
|
|
75
107
|
* directly even when recomputing under its own held transition. These
|
|
76
108
|
* effects deliver applies on a microtask (#2930) instead of the stashed
|
|
77
109
|
* effect queues, so the value must ride the same immediate schedule — a
|
|
78
110
|
* staged value with an immediate apply delivers stale state (resolve) or
|
|
79
111
|
* deadlocks the hold (until). Safe because the node is a private leaf: no
|
|
80
|
-
* subscriber reads an effect's value, only its own apply does. */
|
|
81
|
-
|
|
112
|
+
* subscriber reads an effect's value, only its own apply does. */ const CONFIG_DIRECT_COMMIT = 1 << 15;
|
|
113
|
+
|
|
82
114
|
/** Fresh-pull reader (awaitable `refresh()`'s waiter effect): a read of a
|
|
83
115
|
* dirty source recomputes it inline even when the height gate defers to the
|
|
84
116
|
* flush. Closes the same-flush ordering race where a waiter created
|
|
@@ -87,8 +119,8 @@ export declare const CONFIG_DIRECT_COMMIT: number;
|
|
|
87
119
|
* pending window (async — woken by the settle walk, which runs on every
|
|
88
120
|
* landing including equal-value ones) or serves its sync answer. resolve()
|
|
89
121
|
* deliberately keeps that race — its contract is "first settled value"
|
|
90
|
-
* (#2930), not "next quiescent state". */
|
|
91
|
-
|
|
122
|
+
* (#2930), not "next quiescent state". */ const CONFIG_FRESH_READ = 1 << 16;
|
|
123
|
+
|
|
92
124
|
/** HELD truth (#3164): this node's staged `_pendingValue` is confirming
|
|
93
125
|
* truth riding a transaction that retains optimism, revealed only at that
|
|
94
126
|
* transaction's settle. Two arming sites, one meaning: the store fold
|
|
@@ -103,26 +135,55 @@ export declare const CONFIG_FRESH_READ: number;
|
|
|
103
135
|
* exemption that keeps holds deadlock-free. Override-covered nodes never
|
|
104
136
|
* arm: the override is their display and its revert their notification
|
|
105
137
|
* (A17). Cleared at commit (the commit IS the reveal); subscribers masked
|
|
106
|
-
* during the hold are woken by finalizePureQueue's post-revert pass. */
|
|
107
|
-
|
|
138
|
+
* during the hold are woken by finalizePureQueue's post-revert pass. */ const CONFIG_HELD_TRUTH = 1 << 17;
|
|
139
|
+
|
|
108
140
|
/** SLOT node (store leaf): created through `slotSignal` with `_host`/`_key`
|
|
109
141
|
* backrefs baked into the literal. The unobserved sweep dispatches these to
|
|
110
142
|
* the ONE shared hook (`setSlotUnobserved`) instead of a per-node closure
|
|
111
143
|
* held in a per-node extension — store mounts materialize one signal per
|
|
112
144
|
* touched leaf, so per-node allocations (options object, equals closure,
|
|
113
145
|
* unobserved closure, NodeExtension) were the measured create-floor bytes
|
|
114
|
-
* (warm dbmon profile: store node machinery ~36% + GC ~29%). */
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
146
|
+
* (warm dbmon profile: store node machinery ~36% + GC ~29%). */ const CONFIG_SLOT_NODE = 1 << 18;
|
|
147
|
+
|
|
148
|
+
/** Optimistic node whose own source arrived with a value DIFFERENT from its
|
|
149
|
+
* active override (A18 supersession, #3331). The override survives only as
|
|
150
|
+
* the displayed value — untracked reads and the applied frame keep it until
|
|
151
|
+
* the owning transaction commits — while the graph has already moved to the
|
|
152
|
+
* staged truth in `_pendingValue`: tracked readers see it and the corrected
|
|
153
|
+
* cascade is that transaction's held work. Set by the two own-source write
|
|
154
|
+
* paths (asyncWrite, transition-held recompute); cleared by a fresh optimistic
|
|
155
|
+
* write (a new override re-masks) and by the revert. */ const CONFIG_OVERRIDE_SUPERSEDED = 1 << 19;
|
|
156
|
+
|
|
157
|
+
/** In-flight async node whose inputs were PUBLISHED while it was pending: a
|
|
158
|
+
* batch or transaction committed with the node still `STATUS_PENDING` (an
|
|
159
|
+
* unobserved flight, #3305), so the inputs are on screen and the node's
|
|
160
|
+
* committed `_value` is stale against them. Governs read()'s reveal
|
|
161
|
+
* carve-out: a stale (render) reader in some OTHER transaction may show a
|
|
162
|
+
* foreign-held pending node's committed value — parallel transactions, no
|
|
163
|
+
* entanglement — only while that value is coherent with the visible frame,
|
|
164
|
+
* i.e. while the flight's inputs are themselves held (unpublished) and not
|
|
165
|
+
* lane-revealed. Set by `commitPendingNodes`; cleared when the node next
|
|
166
|
+
* enters pending fresh (a new flight from a settled state). */ const CONFIG_INPUTS_PUBLISHED = 1 << 21;
|
|
167
|
+
|
|
168
|
+
const STATUS_PENDING = 1 << 0;
|
|
169
|
+
|
|
170
|
+
const STATUS_ERROR = 1 << 1;
|
|
171
|
+
|
|
172
|
+
const STATUS_UNINITIALIZED = 1 << 2;
|
|
173
|
+
|
|
174
|
+
const EFFECT_RENDER = 1;
|
|
175
|
+
|
|
176
|
+
const EFFECT_USER = 2;
|
|
177
|
+
|
|
178
|
+
const EFFECT_TRACKED = 3;
|
|
179
|
+
|
|
180
|
+
/** OR-ed into the `type` a lane passes to its effect runners: lane runs
|
|
181
|
+
* apply ahead of their transaction and are exempt from ownership parking. */ const LANE_RUN = 4;
|
|
182
|
+
|
|
183
|
+
const NOT_PENDING = {};
|
|
184
|
+
|
|
185
|
+
const NO_SNAPSHOT = {};
|
|
186
|
+
|
|
126
187
|
/**
|
|
127
188
|
* Stand-in stored in `_overrideValue` for an optimistic write of literal
|
|
128
189
|
* `undefined` (#2898). The slot doubles as the optimistic-node brand
|
|
@@ -131,29 +192,24 @@ export declare const NO_SNAPSHOT: {};
|
|
|
131
192
|
* follow-up writes route off the optimistic path and commit permanently.
|
|
132
193
|
* Same shape as NO_SNAPSHOT. Sites that surface the override VALUE unwrap
|
|
133
194
|
* via `visibleOverrideValue`; slot identity tests stay raw.
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
/** Unwrap an active override's stored value for surfacing to readers (#2898). */
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
195
|
+
*/ const OVERRIDE_UNDEFINED = {};
|
|
196
|
+
|
|
197
|
+
/** Unwrap an active override's stored value for surfacing to readers (#2898). */ function unwrapOverride(E) {
|
|
198
|
+
return E === OVERRIDE_UNDEFINED ? undefined : E;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const STORE_SNAPSHOT_PROPS = "sp";
|
|
202
|
+
|
|
203
|
+
const SUPPORTS_PROXY = typeof Proxy === "function";
|
|
204
|
+
|
|
205
|
+
const defaultContext = {};
|
|
206
|
+
|
|
141
207
|
/**
|
|
142
208
|
* Brand symbol used by `Refreshable<T>` values (projection stores, async
|
|
143
209
|
* memos) to expose their underlying computation to `refresh()`. Not part of
|
|
144
210
|
* the user-facing API.
|
|
145
211
|
*
|
|
146
212
|
* @internal
|
|
147
|
-
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
* Brand applied to values that participate in the `refresh()` re-run protocol.
|
|
151
|
-
* Accessors receive this handle internally; projected stores expose it through
|
|
152
|
-
* their public return type so user-defined hooks that wrap `createOptimisticStore`
|
|
153
|
-
* / `createProjection` / projection-form `createStore` can have their return
|
|
154
|
-
* types inferred without leaking the internal `$REFRESH` symbol into public type
|
|
155
|
-
* signatures (TS4058).
|
|
156
|
-
*/
|
|
157
|
-
export type Refreshable<T> = T & {
|
|
158
|
-
readonly [$REFRESH]: any;
|
|
159
|
-
};
|
|
213
|
+
*/ const $REFRESH = Symbol("refresh");
|
|
214
|
+
|
|
215
|
+
export { $REFRESH, CONFIG_AUTHORITATIVE_OBSERVED, CONFIG_AUTHORITATIVE_READ, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, CONFIG_CHILD_COMPANIONS, CONFIG_DIRECT_COMMIT, CONFIG_FRESH_READ, CONFIG_FW_CHILDREN, CONFIG_HAS_COMPANIONS, CONFIG_HAS_LANE, CONFIG_HAS_SNAPSHOT, CONFIG_HELD_TRUTH, CONFIG_INPUTS_PUBLISHED, CONFIG_IN_SNAPSHOT_SCOPE, CONFIG_NO_SNAPSHOT, CONFIG_OPTIMISTIC, CONFIG_OVERRIDE_SUPERSEDED, CONFIG_OWNED_WRITE, CONFIG_SLOT_NODE, CONFIG_SYNC, CONFIG_TRANSPARENT, EFFECT_RENDER, EFFECT_TRACKED, EFFECT_USER, LANE_RUN, NOT_PENDING, NO_SNAPSHOT, OVERRIDE_UNDEFINED, REACTIVE_CHECK, REACTIVE_DIRTY, REACTIVE_DISPOSED, REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, REACTIVE_LAZY, REACTIVE_MANUAL_WRITE, REACTIVE_MISSED_WAKE, REACTIVE_NONE, REACTIVE_OPTIMISTIC_DIRTY, REACTIVE_REASK, REACTIVE_RECOMPUTING_DEPS, REACTIVE_SNAPSHOT_STALE, REACTIVE_ZOMBIE, STATUS_ERROR, STATUS_PENDING, STATUS_UNINITIALIZED, STORE_SNAPSHOT_PROPS, SUPPORTS_PROXY, defaultContext, unwrapOverride };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
export type ContextRecord = Record<string | symbol, unknown>;
|
|
1
|
+
import { NoOwnerError, ContextNotFoundError } from "./error.js";
|
|
2
|
+
|
|
3
|
+
import { getOwner } from "./owner.js";
|
|
4
|
+
|
|
7
5
|
/**
|
|
8
6
|
* Context provides a form of dependency injection. It is used to save from needing to pass
|
|
9
7
|
* data as props through intermediate components. This function creates a new context object
|
|
@@ -11,8 +9,13 @@ export type ContextRecord = Record<string | symbol, unknown>;
|
|
|
11
9
|
*
|
|
12
10
|
* A default value can be provided here which will be used when a specific value is not provided
|
|
13
11
|
* via a `setContext` call.
|
|
14
|
-
*/
|
|
15
|
-
|
|
12
|
+
*/ function createContext(e, t) {
|
|
13
|
+
return {
|
|
14
|
+
id: Symbol(t),
|
|
15
|
+
defaultValue: e
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
16
19
|
/**
|
|
17
20
|
* Low-level owner-targeted context read. The user-facing read API is
|
|
18
21
|
* `useContext` (in `solid-js`), which wraps this primitive. Exposed here for
|
|
@@ -22,8 +25,19 @@ export declare function createContext<T>(defaultValue?: T, description?: string)
|
|
|
22
25
|
* @throws `ContextNotFoundError` if a context value has not been set yet.
|
|
23
26
|
*
|
|
24
27
|
* @internal
|
|
25
|
-
*/
|
|
26
|
-
|
|
28
|
+
*/ function getContext(e, t = getOwner()) {
|
|
29
|
+
if (!t) {
|
|
30
|
+
throw new NoOwnerError;
|
|
31
|
+
}
|
|
32
|
+
// `undefined` alone means unset — a provided `null` is a value (no `??`).
|
|
33
|
+
let r = t.ft[e.id];
|
|
34
|
+
if (r === undefined) r = e.defaultValue;
|
|
35
|
+
if (r === undefined) {
|
|
36
|
+
throw new ContextNotFoundError;
|
|
37
|
+
}
|
|
38
|
+
return r;
|
|
39
|
+
}
|
|
40
|
+
|
|
27
41
|
/**
|
|
28
42
|
* Low-level owner-targeted context write. The user-facing API is
|
|
29
43
|
* `createContext` (in `solid-js`); its provider component wraps this
|
|
@@ -32,5 +46,16 @@ export declare function getContext<T>(context: Context<T>, owner?: Owner | null)
|
|
|
32
46
|
* @throws `NoOwnerError` if there's no owner at the time of call.
|
|
33
47
|
*
|
|
34
48
|
* @internal
|
|
35
|
-
*/
|
|
36
|
-
|
|
49
|
+
*/ function setContext(e, t, r = getOwner()) {
|
|
50
|
+
if (!r) {
|
|
51
|
+
throw new NoOwnerError;
|
|
52
|
+
}
|
|
53
|
+
// We're creating a new object to avoid child context values being exposed to parent owners. If
|
|
54
|
+
// we don't do this, everything will be a singleton and all hell will break lose.
|
|
55
|
+
r.ft = {
|
|
56
|
+
...r.ft,
|
|
57
|
+
[e.id]: t === undefined ? e.defaultValue : t
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { createContext, getContext, setContext };
|