@angular/core 21.0.0-next.8 → 21.0.0-next.9
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/fesm2022/_attribute-chunk.mjs +1 -1
- package/fesm2022/_debug_node-chunk.mjs +481 -438
- package/fesm2022/_debug_node-chunk.mjs.map +1 -1
- package/fesm2022/_effect-chunk.mjs +512 -48
- package/fesm2022/_effect-chunk.mjs.map +1 -1
- package/fesm2022/{_root_effect_scheduler-chunk.mjs → _effect-chunk2.mjs} +197 -19
- package/fesm2022/_effect-chunk2.mjs.map +1 -0
- package/fesm2022/_not_found-chunk.mjs +1 -1
- package/fesm2022/_resource-chunk.mjs +5 -173
- package/fesm2022/_resource-chunk.mjs.map +1 -1
- package/fesm2022/_untracked-chunk.mjs +117 -0
- package/fesm2022/_untracked-chunk.mjs.map +1 -0
- package/fesm2022/_weak_ref-chunk.mjs +1 -1
- package/fesm2022/core.mjs +8 -7
- package/fesm2022/core.mjs.map +1 -1
- package/fesm2022/primitives-di.mjs +1 -1
- package/fesm2022/primitives-event-dispatch.mjs +1 -1
- package/fesm2022/primitives-signals.mjs +4 -4
- package/fesm2022/primitives-signals.mjs.map +1 -1
- package/fesm2022/rxjs-interop.mjs +5 -5
- package/fesm2022/testing.mjs +3 -3
- package/package.json +2 -2
- package/schematics/bundles/add-bootstrap-context-to-server-main.cjs +5 -5
- package/schematics/bundles/application-config-core.cjs +5 -5
- package/schematics/bundles/{apply_import_manager-CBLmogDD.cjs → apply_import_manager-CoeTX_Ob.cjs} +3 -3
- package/schematics/bundles/bootstrap-options-migration.cjs +5 -5
- package/schematics/bundles/cleanup-unused-imports.cjs +5 -5
- package/schematics/bundles/common-to-standalone-migration.cjs +385 -0
- package/schematics/bundles/{compiler_host-T6xncpiw.cjs → compiler_host-emLDwK2U.cjs} +2 -2
- package/schematics/bundles/control-flow-migration.cjs +4 -4
- package/schematics/bundles/imports-DwPXlGFl.cjs +1 -1
- package/schematics/bundles/{index-DWSaRJdz.cjs → index-CLxYZ09c.cjs} +4 -4
- package/schematics/bundles/{index-BnmACOsq.cjs → index-Dvqnp6JS.cjs} +166 -66
- package/schematics/bundles/inject-migration.cjs +3 -3
- package/schematics/bundles/leading_space-D9nQ8UQC.cjs +1 -1
- package/schematics/bundles/{migrate_ts_type_references-Cu-FR4L5.cjs → migrate_ts_type_references-CpM5FPGa.cjs} +5 -5
- package/schematics/bundles/{ng_component_template-BkWiUuGG.cjs → ng_component_template-BRbBIAUX.cjs} +2 -2
- package/schematics/bundles/ng_decorators-BI0uV7KI.cjs +1 -1
- package/schematics/bundles/ngclass-to-class-migration.cjs +7 -7
- package/schematics/bundles/ngstyle-to-style-migration.cjs +7 -7
- package/schematics/bundles/nodes-B16H9JUd.cjs +1 -1
- package/schematics/bundles/output-migration.cjs +6 -6
- package/schematics/bundles/{parse_html-C97tKKp3.cjs → parse_html-CPWfkfhR.cjs} +2 -2
- package/schematics/bundles/{project_paths-C6g3lqjX.cjs → project_paths-C8H7KDJ3.cjs} +3 -3
- package/schematics/bundles/{project_tsconfig_paths-CdhVNYMk.cjs → project_tsconfig_paths-CiBzGSIa.cjs} +12 -4
- package/schematics/bundles/property_name-BBwFuqMe.cjs +1 -1
- package/schematics/bundles/route-lazy-loading.cjs +3 -3
- package/schematics/bundles/router-current-navigation.cjs +4 -4
- package/schematics/bundles/router-last-successful-navigation.cjs +4 -4
- package/schematics/bundles/router-testing-module-migration.cjs +5 -5
- package/schematics/bundles/self-closing-tags-migration.cjs +6 -6
- package/schematics/bundles/signal-input-migration.cjs +7 -7
- package/schematics/bundles/signal-queries-migration.cjs +7 -7
- package/schematics/bundles/signals.cjs +7 -7
- package/schematics/bundles/standalone-migration.cjs +4 -4
- package/schematics/bundles/symbol-BObKoqes.cjs +1 -1
- package/schematics/collection.json +6 -0
- package/schematics/migrations/common-to-standalone-migration/schema.json +14 -0
- package/types/_api-chunk.d.ts +1 -1
- package/types/_chrome_dev_tools_performance-chunk.d.ts +20 -12
- package/types/_discovery-chunk.d.ts +12 -6
- package/types/_effect-chunk.d.ts +1 -1
- package/types/_event_dispatcher-chunk.d.ts +1 -1
- package/types/_formatter-chunk.d.ts +4 -3
- package/types/_weak_ref-chunk.d.ts +1 -1
- package/types/core.d.ts +49 -20
- package/types/primitives-di.d.ts +1 -1
- package/types/primitives-event-dispatch.d.ts +1 -1
- package/types/primitives-signals.d.ts +2 -2
- package/types/rxjs-interop.d.ts +1 -1
- package/types/testing.d.ts +1 -1
- package/fesm2022/_root_effect_scheduler-chunk.mjs.map +0 -1
- package/fesm2022/_signal-chunk.mjs +0 -581
- package/fesm2022/_signal-chunk.mjs.map +0 -1
|
@@ -1,19 +1,409 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.0.0-next.
|
|
2
|
+
* @license Angular v21.0.0-next.9
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The currently active consumer `ReactiveNode`, if running code in a reactive context.
|
|
9
|
+
*
|
|
10
|
+
* Change this via `setActiveConsumer`.
|
|
11
|
+
*/
|
|
12
|
+
let activeConsumer = null;
|
|
13
|
+
let inNotificationPhase = false;
|
|
14
|
+
/**
|
|
15
|
+
* Global epoch counter. Incremented whenever a source signal is set.
|
|
16
|
+
*/
|
|
17
|
+
let epoch = 1;
|
|
18
|
+
/**
|
|
19
|
+
* If set, called after a producer `ReactiveNode` is created.
|
|
20
|
+
*/
|
|
21
|
+
let postProducerCreatedFn = null;
|
|
22
|
+
/**
|
|
23
|
+
* Symbol used to tell `Signal`s apart from other functions.
|
|
24
|
+
*
|
|
25
|
+
* This can be used to auto-unwrap signals in various cases, or to auto-wrap non-signal values.
|
|
26
|
+
*/
|
|
27
|
+
const SIGNAL = /* @__PURE__ */ Symbol('SIGNAL');
|
|
28
|
+
function setActiveConsumer(consumer) {
|
|
29
|
+
const prev = activeConsumer;
|
|
30
|
+
activeConsumer = consumer;
|
|
31
|
+
return prev;
|
|
32
|
+
}
|
|
33
|
+
function getActiveConsumer() {
|
|
34
|
+
return activeConsumer;
|
|
35
|
+
}
|
|
36
|
+
function isInNotificationPhase() {
|
|
37
|
+
return inNotificationPhase;
|
|
38
|
+
}
|
|
39
|
+
function isReactive(value) {
|
|
40
|
+
return value[SIGNAL] !== undefined;
|
|
41
|
+
}
|
|
42
|
+
const REACTIVE_NODE = {
|
|
43
|
+
version: 0,
|
|
44
|
+
lastCleanEpoch: 0,
|
|
45
|
+
dirty: false,
|
|
46
|
+
producers: undefined,
|
|
47
|
+
producersTail: undefined,
|
|
48
|
+
consumers: undefined,
|
|
49
|
+
consumersTail: undefined,
|
|
50
|
+
recomputing: false,
|
|
51
|
+
consumerAllowSignalWrites: false,
|
|
52
|
+
consumerIsAlwaysLive: false,
|
|
53
|
+
kind: 'unknown',
|
|
54
|
+
producerMustRecompute: () => false,
|
|
55
|
+
producerRecomputeValue: () => { },
|
|
56
|
+
consumerMarkedDirty: () => { },
|
|
57
|
+
consumerOnSignalRead: () => { },
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Called by implementations when a producer's signal is read.
|
|
61
|
+
*/
|
|
62
|
+
function producerAccessed(node) {
|
|
63
|
+
if (inNotificationPhase) {
|
|
64
|
+
throw new Error(typeof ngDevMode !== 'undefined' && ngDevMode
|
|
65
|
+
? `Assertion error: signal read during notification phase`
|
|
66
|
+
: '');
|
|
67
|
+
}
|
|
68
|
+
if (activeConsumer === null) {
|
|
69
|
+
// Accessed outside of a reactive context, so nothing to record.
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
activeConsumer.consumerOnSignalRead(node);
|
|
73
|
+
const prevProducerLink = activeConsumer.producersTail;
|
|
74
|
+
// If the last producer we accessed is the same as the current one, we can skip adding a new
|
|
75
|
+
// link
|
|
76
|
+
if (prevProducerLink !== undefined && prevProducerLink.producer === node) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let nextProducerLink = undefined;
|
|
80
|
+
const isRecomputing = activeConsumer.recomputing;
|
|
81
|
+
if (isRecomputing) {
|
|
82
|
+
// If we're incrementally rebuilding the producers list, we want to check if the next producer
|
|
83
|
+
// in the list is the same as the one we're trying to add.
|
|
84
|
+
// If the previous producer is defined, then the next producer is just the one that follows it.
|
|
85
|
+
// Otherwise, we should check the head of the producers list (the first node that we accessed the last time this consumer was run).
|
|
86
|
+
nextProducerLink =
|
|
87
|
+
prevProducerLink !== undefined ? prevProducerLink.nextProducer : activeConsumer.producers;
|
|
88
|
+
if (nextProducerLink !== undefined && nextProducerLink.producer === node) {
|
|
89
|
+
// If the next producer is the same as the one we're trying to add, we can just update the
|
|
90
|
+
// last read version, update the tail of the producers list of this rerun, and return.
|
|
91
|
+
activeConsumer.producersTail = nextProducerLink;
|
|
92
|
+
nextProducerLink.lastReadVersion = node.version;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const prevConsumerLink = node.consumersTail;
|
|
97
|
+
// If the producer we're accessing already has a link to this consumer, we can skip adding a new
|
|
98
|
+
// link. This can short circuit the creation of a new link in the case where the consumer reads alternating ReeactiveNodes
|
|
99
|
+
if (prevConsumerLink !== undefined &&
|
|
100
|
+
prevConsumerLink.consumer === activeConsumer &&
|
|
101
|
+
// However, we have to make sure that the link we've discovered isn't from a node that is incrementally rebuilding its producer list
|
|
102
|
+
(!isRecomputing || isValidLink(prevConsumerLink, activeConsumer))) {
|
|
103
|
+
// If we found an existing link to the consumer we can just return.
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// If we got here, it means that we need to create a new link between the producer and the consumer.
|
|
107
|
+
const isLive = consumerIsLive(activeConsumer);
|
|
108
|
+
const newLink = {
|
|
109
|
+
producer: node,
|
|
110
|
+
consumer: activeConsumer,
|
|
111
|
+
// instead of eagerly destroying the previous link, we delay until we've finished recomputing
|
|
112
|
+
// the producers list, so that we can destroy all of the old links at once.
|
|
113
|
+
nextProducer: nextProducerLink,
|
|
114
|
+
prevConsumer: prevConsumerLink,
|
|
115
|
+
lastReadVersion: node.version,
|
|
116
|
+
nextConsumer: undefined,
|
|
117
|
+
};
|
|
118
|
+
activeConsumer.producersTail = newLink;
|
|
119
|
+
if (prevProducerLink !== undefined) {
|
|
120
|
+
prevProducerLink.nextProducer = newLink;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
activeConsumer.producers = newLink;
|
|
124
|
+
}
|
|
125
|
+
if (isLive) {
|
|
126
|
+
producerAddLiveConsumer(node, newLink);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Increment the global epoch counter.
|
|
131
|
+
*
|
|
132
|
+
* Called by source producers (that is, not computeds) whenever their values change.
|
|
133
|
+
*/
|
|
134
|
+
function producerIncrementEpoch() {
|
|
135
|
+
epoch++;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Ensure this producer's `version` is up-to-date.
|
|
139
|
+
*/
|
|
140
|
+
function producerUpdateValueVersion(node) {
|
|
141
|
+
if (consumerIsLive(node) && !node.dirty) {
|
|
142
|
+
// A live consumer will be marked dirty by producers, so a clean state means that its version
|
|
143
|
+
// is guaranteed to be up-to-date.
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (!node.dirty && node.lastCleanEpoch === epoch) {
|
|
147
|
+
// Even non-live consumers can skip polling if they previously found themselves to be clean at
|
|
148
|
+
// the current epoch, since their dependencies could not possibly have changed (such a change
|
|
149
|
+
// would've increased the epoch).
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (!node.producerMustRecompute(node) && !consumerPollProducersForChange(node)) {
|
|
153
|
+
// None of our producers report a change since the last time they were read, so no
|
|
154
|
+
// recomputation of our value is necessary, and we can consider ourselves clean.
|
|
155
|
+
producerMarkClean(node);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
node.producerRecomputeValue(node);
|
|
159
|
+
// After recomputing the value, we're no longer dirty.
|
|
160
|
+
producerMarkClean(node);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Propagate a dirty notification to live consumers of this producer.
|
|
164
|
+
*/
|
|
165
|
+
function producerNotifyConsumers(node) {
|
|
166
|
+
if (node.consumers === undefined) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
// Prevent signal reads when we're updating the graph
|
|
170
|
+
const prev = inNotificationPhase;
|
|
171
|
+
inNotificationPhase = true;
|
|
172
|
+
try {
|
|
173
|
+
for (let link = node.consumers; link !== undefined; link = link.nextConsumer) {
|
|
174
|
+
const consumer = link.consumer;
|
|
175
|
+
if (!consumer.dirty) {
|
|
176
|
+
consumerMarkDirty(consumer);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
inNotificationPhase = prev;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Whether this `ReactiveNode` in its producer capacity is currently allowed to initiate updates,
|
|
186
|
+
* based on the current consumer context.
|
|
187
|
+
*/
|
|
188
|
+
function producerUpdatesAllowed() {
|
|
189
|
+
return activeConsumer?.consumerAllowSignalWrites !== false;
|
|
190
|
+
}
|
|
191
|
+
function consumerMarkDirty(node) {
|
|
192
|
+
node.dirty = true;
|
|
193
|
+
producerNotifyConsumers(node);
|
|
194
|
+
node.consumerMarkedDirty?.(node);
|
|
195
|
+
}
|
|
196
|
+
function producerMarkClean(node) {
|
|
197
|
+
node.dirty = false;
|
|
198
|
+
node.lastCleanEpoch = epoch;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Prepare this consumer to run a computation in its reactive context and set
|
|
202
|
+
* it as the active consumer.
|
|
203
|
+
*
|
|
204
|
+
* Must be called by subclasses which represent reactive computations, before those computations
|
|
205
|
+
* begin.
|
|
206
|
+
*/
|
|
207
|
+
function consumerBeforeComputation(node) {
|
|
208
|
+
if (node)
|
|
209
|
+
resetConsumerBeforeComputation(node);
|
|
210
|
+
return setActiveConsumer(node);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Prepare this consumer to run a computation in its reactive context.
|
|
214
|
+
*
|
|
215
|
+
* We expose this mainly for code where we manually batch effects into a single
|
|
216
|
+
* consumer. In those cases we may wish to "reopen" a consumer multiple times
|
|
217
|
+
* in initial render before finalizing it. Most code should just call
|
|
218
|
+
* `consumerBeforeComputation` instead of calling this directly.
|
|
219
|
+
*/
|
|
220
|
+
function resetConsumerBeforeComputation(node) {
|
|
221
|
+
node.producersTail = undefined;
|
|
222
|
+
node.recomputing = true;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Finalize this consumer's state and set previous consumer as the active consumer after a
|
|
226
|
+
* reactive computation has run.
|
|
227
|
+
*
|
|
228
|
+
* Must be called by subclasses which represent reactive computations, after those computations
|
|
229
|
+
* have finished.
|
|
230
|
+
*/
|
|
231
|
+
function consumerAfterComputation(node, prevConsumer) {
|
|
232
|
+
setActiveConsumer(prevConsumer);
|
|
233
|
+
if (node)
|
|
234
|
+
finalizeConsumerAfterComputation(node);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Finalize this consumer's state after a reactive computation has run.
|
|
238
|
+
*
|
|
239
|
+
* We expose this mainly for code where we manually batch effects into a single
|
|
240
|
+
* consumer. In those cases we may wish to "reopen" a consumer multiple times
|
|
241
|
+
* in initial render before finalizing it. Most code should just call
|
|
242
|
+
* `consumerAfterComputation` instead of calling this directly.
|
|
243
|
+
*/
|
|
244
|
+
function finalizeConsumerAfterComputation(node) {
|
|
245
|
+
node.recomputing = false;
|
|
246
|
+
// We've finished incrementally rebuilding the producers list, now if there are any producers
|
|
247
|
+
// that are after producersTail, they are stale and should be removed.
|
|
248
|
+
const producersTail = node.producersTail;
|
|
249
|
+
let toRemove = producersTail !== undefined ? producersTail.nextProducer : node.producers;
|
|
250
|
+
if (toRemove !== undefined) {
|
|
251
|
+
if (consumerIsLive(node)) {
|
|
252
|
+
// For each stale link, we first unlink it from the producers list of consumers
|
|
253
|
+
do {
|
|
254
|
+
toRemove = producerRemoveLiveConsumerLink(toRemove);
|
|
255
|
+
} while (toRemove !== undefined);
|
|
256
|
+
}
|
|
257
|
+
// Now, we can truncate the producers list to remove all stale links.
|
|
258
|
+
if (producersTail !== undefined) {
|
|
259
|
+
producersTail.nextProducer = undefined;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
node.producers = undefined;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Determine whether this consumer has any dependencies which have changed since the last time
|
|
268
|
+
* they were read.
|
|
269
|
+
*/
|
|
270
|
+
function consumerPollProducersForChange(node) {
|
|
271
|
+
// Poll producers for change.
|
|
272
|
+
for (let link = node.producers; link !== undefined; link = link.nextProducer) {
|
|
273
|
+
const producer = link.producer;
|
|
274
|
+
const seenVersion = link.lastReadVersion;
|
|
275
|
+
// First check the versions. A mismatch means that the producer's value is known to have
|
|
276
|
+
// changed since the last time we read it.
|
|
277
|
+
if (seenVersion !== producer.version) {
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
// The producer's version is the same as the last time we read it, but it might itself be
|
|
281
|
+
// stale. Force the producer to recompute its version (calculating a new value if necessary).
|
|
282
|
+
producerUpdateValueVersion(producer);
|
|
283
|
+
// Now when we do this check, `producer.version` is guaranteed to be up to date, so if the
|
|
284
|
+
// versions still match then it has not changed since the last time we read it.
|
|
285
|
+
if (seenVersion !== producer.version) {
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Disconnect this consumer from the graph.
|
|
293
|
+
*/
|
|
294
|
+
function consumerDestroy(node) {
|
|
295
|
+
if (consumerIsLive(node)) {
|
|
296
|
+
// Drop all connections from the graph to this node.
|
|
297
|
+
let link = node.producers;
|
|
298
|
+
while (link !== undefined) {
|
|
299
|
+
link = producerRemoveLiveConsumerLink(link);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// Truncate all the linked lists to drop all connection from this node to the graph.
|
|
303
|
+
node.producers = undefined;
|
|
304
|
+
node.producersTail = undefined;
|
|
305
|
+
node.consumers = undefined;
|
|
306
|
+
node.consumersTail = undefined;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Add `consumer` as a live consumer of this node.
|
|
310
|
+
*
|
|
311
|
+
* Note that this operation is potentially transitive. If this node becomes live, then it becomes
|
|
312
|
+
* a live consumer of all of its current producers.
|
|
313
|
+
*/
|
|
314
|
+
function producerAddLiveConsumer(node, link) {
|
|
315
|
+
const consumersTail = node.consumersTail;
|
|
316
|
+
const wasLive = consumerIsLive(node);
|
|
317
|
+
if (consumersTail !== undefined) {
|
|
318
|
+
link.nextConsumer = consumersTail.nextConsumer;
|
|
319
|
+
consumersTail.nextConsumer = link;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
link.nextConsumer = undefined;
|
|
323
|
+
node.consumers = link;
|
|
324
|
+
}
|
|
325
|
+
link.prevConsumer = consumersTail;
|
|
326
|
+
node.consumersTail = link;
|
|
327
|
+
if (!wasLive) {
|
|
328
|
+
for (let link = node.producers; link !== undefined; link = link.nextProducer) {
|
|
329
|
+
producerAddLiveConsumer(link.producer, link);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function producerRemoveLiveConsumerLink(link) {
|
|
334
|
+
const producer = link.producer;
|
|
335
|
+
const nextProducer = link.nextProducer;
|
|
336
|
+
const nextConsumer = link.nextConsumer;
|
|
337
|
+
const prevConsumer = link.prevConsumer;
|
|
338
|
+
link.nextConsumer = undefined;
|
|
339
|
+
link.prevConsumer = undefined;
|
|
340
|
+
if (nextConsumer !== undefined) {
|
|
341
|
+
nextConsumer.prevConsumer = prevConsumer;
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
producer.consumersTail = prevConsumer;
|
|
345
|
+
}
|
|
346
|
+
if (prevConsumer !== undefined) {
|
|
347
|
+
prevConsumer.nextConsumer = nextConsumer;
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
producer.consumers = nextConsumer;
|
|
351
|
+
if (!consumerIsLive(producer)) {
|
|
352
|
+
let producerLink = producer.producers;
|
|
353
|
+
while (producerLink !== undefined) {
|
|
354
|
+
producerLink = producerRemoveLiveConsumerLink(producerLink);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return nextProducer;
|
|
359
|
+
}
|
|
360
|
+
function consumerIsLive(node) {
|
|
361
|
+
return node.consumerIsAlwaysLive || node.consumers !== undefined;
|
|
362
|
+
}
|
|
363
|
+
function runPostProducerCreatedFn(node) {
|
|
364
|
+
postProducerCreatedFn?.(node);
|
|
365
|
+
}
|
|
366
|
+
function setPostProducerCreatedFn(fn) {
|
|
367
|
+
const prev = postProducerCreatedFn;
|
|
368
|
+
postProducerCreatedFn = fn;
|
|
369
|
+
return prev;
|
|
370
|
+
}
|
|
371
|
+
// While a ReactiveNode is recomputing, it may not have destroyed previous links
|
|
372
|
+
// This allows us to check if a given link will be destroyed by a reactivenode if it were to finish running immediately without accesing any more producers
|
|
373
|
+
function isValidLink(checkLink, consumer) {
|
|
374
|
+
const producersTail = consumer.producersTail;
|
|
375
|
+
if (producersTail !== undefined) {
|
|
376
|
+
let link = consumer.producers;
|
|
377
|
+
do {
|
|
378
|
+
if (link === checkLink) {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
if (link === producersTail) {
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
link = link.nextProducer;
|
|
385
|
+
} while (link !== undefined);
|
|
386
|
+
}
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
8
389
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
390
|
+
/**
|
|
391
|
+
* The default equality function used for `signal` and `computed`, which uses referential equality.
|
|
392
|
+
*/
|
|
393
|
+
function defaultEquals(a, b) {
|
|
394
|
+
return Object.is(a, b);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Create a computed signal which derives a reactive value from an expression.
|
|
399
|
+
*/
|
|
400
|
+
function createComputed(computation, equal) {
|
|
401
|
+
const node = Object.create(COMPUTED_NODE);
|
|
402
|
+
node.computation = computation;
|
|
403
|
+
if (equal !== undefined) {
|
|
404
|
+
node.equal = equal;
|
|
405
|
+
}
|
|
406
|
+
const computed = () => {
|
|
17
407
|
// Check if the value needs updating before returning it.
|
|
18
408
|
producerUpdateValueVersion(node);
|
|
19
409
|
// Record that someone looked at this signal.
|
|
@@ -23,36 +413,42 @@ function createLinkedSignal(sourceFn, computationFn, equalityFn) {
|
|
|
23
413
|
}
|
|
24
414
|
return node.value;
|
|
25
415
|
};
|
|
26
|
-
|
|
27
|
-
getter[SIGNAL] = node;
|
|
416
|
+
computed[SIGNAL] = node;
|
|
28
417
|
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
29
418
|
const debugName = node.debugName ? ' (' + node.debugName + ')' : '';
|
|
30
|
-
|
|
419
|
+
computed.toString = () => `[Computed${debugName}: ${node.value}]`;
|
|
31
420
|
}
|
|
32
421
|
runPostProducerCreatedFn(node);
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
function linkedSignalSetFn(node, newValue) {
|
|
36
|
-
producerUpdateValueVersion(node);
|
|
37
|
-
signalSetFn(node, newValue);
|
|
38
|
-
producerMarkClean(node);
|
|
39
|
-
}
|
|
40
|
-
function linkedSignalUpdateFn(node, updater) {
|
|
41
|
-
producerUpdateValueVersion(node);
|
|
42
|
-
signalUpdateFn(node, updater);
|
|
43
|
-
producerMarkClean(node);
|
|
422
|
+
return computed;
|
|
44
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* A dedicated symbol used before a computed value has been calculated for the first time.
|
|
426
|
+
* Explicitly typed as `any` so we can use it as signal's value.
|
|
427
|
+
*/
|
|
428
|
+
const UNSET = /* @__PURE__ */ Symbol('UNSET');
|
|
429
|
+
/**
|
|
430
|
+
* A dedicated symbol used in place of a computed signal value to indicate that a given computation
|
|
431
|
+
* is in progress. Used to detect cycles in computation chains.
|
|
432
|
+
* Explicitly typed as `any` so we can use it as signal's value.
|
|
433
|
+
*/
|
|
434
|
+
const COMPUTING = /* @__PURE__ */ Symbol('COMPUTING');
|
|
435
|
+
/**
|
|
436
|
+
* A dedicated symbol used in place of a computed signal value to indicate that a given computation
|
|
437
|
+
* failed. The thrown error is cached until the computation gets dirty again.
|
|
438
|
+
* Explicitly typed as `any` so we can use it as signal's value.
|
|
439
|
+
*/
|
|
440
|
+
const ERRORED = /* @__PURE__ */ Symbol('ERRORED');
|
|
45
441
|
// Note: Using an IIFE here to ensure that the spread assignment is not considered
|
|
46
|
-
// a side-effect, ending up preserving `
|
|
442
|
+
// a side-effect, ending up preserving `COMPUTED_NODE` and `REACTIVE_NODE`.
|
|
47
443
|
// TODO: remove when https://github.com/evanw/esbuild/issues/3392 is resolved.
|
|
48
|
-
const
|
|
444
|
+
const COMPUTED_NODE = /* @__PURE__ */ (() => {
|
|
49
445
|
return {
|
|
50
446
|
...REACTIVE_NODE,
|
|
51
447
|
value: UNSET,
|
|
52
448
|
dirty: true,
|
|
53
449
|
error: null,
|
|
54
450
|
equal: defaultEquals,
|
|
55
|
-
kind: '
|
|
451
|
+
kind: 'computed',
|
|
56
452
|
producerMustRecompute(node) {
|
|
57
453
|
// Force a recomputation if there's no current value, or if the current value is in the
|
|
58
454
|
// process of being calculated (which should throw an error).
|
|
@@ -67,16 +463,17 @@ const LINKED_SIGNAL_NODE = /* @__PURE__ */ (() => {
|
|
|
67
463
|
node.value = COMPUTING;
|
|
68
464
|
const prevConsumer = consumerBeforeComputation(node);
|
|
69
465
|
let newValue;
|
|
466
|
+
let wasEqual = false;
|
|
70
467
|
try {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
468
|
+
newValue = node.computation();
|
|
469
|
+
// We want to mark this node as errored if calling `equal` throws; however, we don't want
|
|
470
|
+
// to track any reactive reads inside `equal`.
|
|
471
|
+
setActiveConsumer(null);
|
|
472
|
+
wasEqual =
|
|
473
|
+
oldValue !== UNSET &&
|
|
474
|
+
oldValue !== ERRORED &&
|
|
475
|
+
newValue !== ERRORED &&
|
|
476
|
+
node.equal(oldValue, newValue);
|
|
80
477
|
}
|
|
81
478
|
catch (err) {
|
|
82
479
|
newValue = ERRORED;
|
|
@@ -85,7 +482,7 @@ const LINKED_SIGNAL_NODE = /* @__PURE__ */ (() => {
|
|
|
85
482
|
finally {
|
|
86
483
|
consumerAfterComputation(node, prevConsumer);
|
|
87
484
|
}
|
|
88
|
-
if (
|
|
485
|
+
if (wasEqual) {
|
|
89
486
|
// No change to `valueVersion` - old and new values are
|
|
90
487
|
// semantically equivalent.
|
|
91
488
|
node.value = oldValue;
|
|
@@ -97,21 +494,88 @@ const LINKED_SIGNAL_NODE = /* @__PURE__ */ (() => {
|
|
|
97
494
|
};
|
|
98
495
|
})();
|
|
99
496
|
|
|
497
|
+
function defaultThrowError() {
|
|
498
|
+
throw new Error();
|
|
499
|
+
}
|
|
500
|
+
let throwInvalidWriteToSignalErrorFn = defaultThrowError;
|
|
501
|
+
function throwInvalidWriteToSignalError(node) {
|
|
502
|
+
throwInvalidWriteToSignalErrorFn(node);
|
|
503
|
+
}
|
|
504
|
+
function setThrowInvalidWriteToSignalError(fn) {
|
|
505
|
+
throwInvalidWriteToSignalErrorFn = fn;
|
|
506
|
+
}
|
|
507
|
+
|
|
100
508
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
509
|
+
* If set, called after `WritableSignal`s are updated.
|
|
510
|
+
*
|
|
511
|
+
* This hook can be used to achieve various effects, such as running effects synchronously as part
|
|
512
|
+
* of setting a signal.
|
|
103
513
|
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
514
|
+
let postSignalSetFn = null;
|
|
515
|
+
/**
|
|
516
|
+
* Creates a `Signal` getter, setter, and updater function.
|
|
517
|
+
*/
|
|
518
|
+
function createSignal(initialValue, equal) {
|
|
519
|
+
const node = Object.create(SIGNAL_NODE);
|
|
520
|
+
node.value = initialValue;
|
|
521
|
+
if (equal !== undefined) {
|
|
522
|
+
node.equal = equal;
|
|
110
523
|
}
|
|
111
|
-
|
|
112
|
-
|
|
524
|
+
const getter = (() => signalGetFn(node));
|
|
525
|
+
getter[SIGNAL] = node;
|
|
526
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
527
|
+
const debugName = node.debugName ? ' (' + node.debugName + ')' : '';
|
|
528
|
+
getter.toString = () => `[Signal${debugName}: ${node.value}]`;
|
|
529
|
+
}
|
|
530
|
+
runPostProducerCreatedFn(node);
|
|
531
|
+
const set = (newValue) => signalSetFn(node, newValue);
|
|
532
|
+
const update = (updateFn) => signalUpdateFn(node, updateFn);
|
|
533
|
+
return [getter, set, update];
|
|
534
|
+
}
|
|
535
|
+
function setPostSignalSetFn(fn) {
|
|
536
|
+
const prev = postSignalSetFn;
|
|
537
|
+
postSignalSetFn = fn;
|
|
538
|
+
return prev;
|
|
539
|
+
}
|
|
540
|
+
function signalGetFn(node) {
|
|
541
|
+
producerAccessed(node);
|
|
542
|
+
return node.value;
|
|
543
|
+
}
|
|
544
|
+
function signalSetFn(node, newValue) {
|
|
545
|
+
if (!producerUpdatesAllowed()) {
|
|
546
|
+
throwInvalidWriteToSignalError(node);
|
|
547
|
+
}
|
|
548
|
+
if (!node.equal(node.value, newValue)) {
|
|
549
|
+
node.value = newValue;
|
|
550
|
+
signalValueChanged(node);
|
|
113
551
|
}
|
|
114
552
|
}
|
|
553
|
+
function signalUpdateFn(node, updater) {
|
|
554
|
+
if (!producerUpdatesAllowed()) {
|
|
555
|
+
throwInvalidWriteToSignalError(node);
|
|
556
|
+
}
|
|
557
|
+
signalSetFn(node, updater(node.value));
|
|
558
|
+
}
|
|
559
|
+
function runPostSignalSetFn(node) {
|
|
560
|
+
postSignalSetFn?.(node);
|
|
561
|
+
}
|
|
562
|
+
// Note: Using an IIFE here to ensure that the spread assignment is not considered
|
|
563
|
+
// a side-effect, ending up preserving `COMPUTED_NODE` and `REACTIVE_NODE`.
|
|
564
|
+
// TODO: remove when https://github.com/evanw/esbuild/issues/3392 is resolved.
|
|
565
|
+
const SIGNAL_NODE = /* @__PURE__ */ (() => {
|
|
566
|
+
return {
|
|
567
|
+
...REACTIVE_NODE,
|
|
568
|
+
equal: defaultEquals,
|
|
569
|
+
value: undefined,
|
|
570
|
+
kind: 'signal',
|
|
571
|
+
};
|
|
572
|
+
})();
|
|
573
|
+
function signalValueChanged(node) {
|
|
574
|
+
node.version++;
|
|
575
|
+
producerIncrementEpoch();
|
|
576
|
+
producerNotifyConsumers(node);
|
|
577
|
+
postSignalSetFn?.(node);
|
|
578
|
+
}
|
|
115
579
|
|
|
116
580
|
const BASE_EFFECT_NODE =
|
|
117
581
|
/* @__PURE__ */ (() => ({
|
|
@@ -137,5 +601,5 @@ function runEffect(node) {
|
|
|
137
601
|
}
|
|
138
602
|
}
|
|
139
603
|
|
|
140
|
-
export { BASE_EFFECT_NODE,
|
|
604
|
+
export { BASE_EFFECT_NODE, COMPUTING, ERRORED, REACTIVE_NODE, SIGNAL, SIGNAL_NODE, UNSET, consumerAfterComputation, consumerBeforeComputation, consumerDestroy, consumerMarkDirty, consumerPollProducersForChange, createComputed, createSignal, defaultEquals, finalizeConsumerAfterComputation, getActiveConsumer, isInNotificationPhase, isReactive, producerAccessed, producerIncrementEpoch, producerMarkClean, producerNotifyConsumers, producerUpdateValueVersion, producerUpdatesAllowed, resetConsumerBeforeComputation, runEffect, runPostProducerCreatedFn, runPostSignalSetFn, setActiveConsumer, setPostProducerCreatedFn, setPostSignalSetFn, setThrowInvalidWriteToSignalError, signalGetFn, signalSetFn, signalUpdateFn };
|
|
141
605
|
//# sourceMappingURL=_effect-chunk.mjs.map
|