@tstdl/base 0.93.181 → 0.93.183
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/api/server/api-request-token.provider.js +1 -1
- package/api/server/gateway.js +8 -3
- package/authentication/authentication.api.d.ts +13 -40
- package/authentication/authentication.api.js +5 -14
- package/authentication/client/authentication.service.d.ts +6 -14
- package/authentication/client/authentication.service.js +22 -4
- package/authentication/client/module.d.ts +1 -1
- package/authentication/client/module.js +4 -4
- package/authentication/models/index.d.ts +1 -0
- package/authentication/models/index.js +1 -0
- package/authentication/models/totp-results.model.d.ts +11 -0
- package/authentication/models/totp-results.model.js +37 -0
- package/authentication/server/authentication.api-controller.d.ts +3 -3
- package/authentication/server/authentication.api-controller.js +31 -4
- package/authentication/server/authentication.service.d.ts +5 -14
- package/authentication/server/authentication.service.js +6 -4
- package/core.d.ts +0 -5
- package/core.js +0 -8
- package/document-management/api/document-management.api.d.ts +2 -2
- package/document-management/service-models/document.service-model.d.ts +1 -1
- package/examples/config.d.ts +25 -0
- package/examples/config.js +26 -0
- package/notification/server/module.d.ts +1 -1
- package/notification/server/module.js +1 -1
- package/package.json +5 -5
- package/signals/api.d.ts +5 -1
- package/signals/api.js +3 -1
- package/signals/implementation/api.d.ts +13 -5
- package/signals/implementation/api.js +7 -1
- package/signals/implementation/asserts.d.ts +2 -2
- package/signals/implementation/asserts.js +3 -3
- package/signals/implementation/computed.d.ts +7 -34
- package/signals/implementation/computed.js +14 -83
- package/signals/implementation/configure.js +6 -2
- package/signals/implementation/effect.d.ts +65 -46
- package/signals/implementation/effect.js +97 -62
- package/signals/implementation/index.d.ts +2 -4
- package/signals/implementation/index.js +2 -4
- package/signals/implementation/linked_signal.d.ts +36 -0
- package/signals/implementation/linked_signal.js +34 -0
- package/signals/implementation/primitive/computed.d.ts +55 -0
- package/signals/implementation/primitive/computed.js +107 -0
- package/signals/implementation/primitive/effect.d.ts +26 -0
- package/signals/implementation/primitive/effect.js +31 -0
- package/signals/implementation/{equality.d.ts → primitive/equality.d.ts} +1 -1
- package/signals/implementation/{equality.js → primitive/equality.js} +1 -1
- package/signals/implementation/primitive/errors.d.ts +10 -0
- package/signals/implementation/{errors.js → primitive/errors.js} +3 -4
- package/signals/implementation/primitive/formatter.d.ts +19 -0
- package/signals/implementation/primitive/formatter.js +136 -0
- package/signals/implementation/{graph.d.ts → primitive/graph.d.ts} +68 -36
- package/signals/implementation/primitive/graph.js +386 -0
- package/signals/implementation/primitive/linked_signal.d.ts +46 -0
- package/signals/implementation/primitive/linked_signal.js +110 -0
- package/signals/implementation/primitive/signal.d.ts +31 -0
- package/signals/implementation/primitive/signal.js +80 -0
- package/signals/implementation/primitive/untracked.d.ts +12 -0
- package/signals/implementation/primitive/untracked.js +23 -0
- package/signals/implementation/{watch.d.ts → primitive/watch.d.ts} +1 -2
- package/signals/implementation/{watch.js → primitive/watch.js} +22 -16
- package/signals/implementation/resource/api.d.ts +275 -0
- package/signals/implementation/resource/api.js +26 -0
- package/signals/implementation/resource/debounce.d.ts +13 -0
- package/signals/implementation/resource/debounce.js +113 -0
- package/signals/implementation/resource/from_snapshots.d.ts +16 -0
- package/signals/implementation/resource/from_snapshots.js +44 -0
- package/signals/implementation/resource/index.d.ts +11 -0
- package/signals/implementation/resource/index.js +11 -0
- package/signals/implementation/resource/resource.d.ts +110 -0
- package/signals/implementation/resource/resource.js +402 -0
- package/signals/implementation/root_effect_scheduler.d.ts +50 -0
- package/signals/implementation/root_effect_scheduler.js +66 -0
- package/signals/implementation/signal.d.ts +42 -18
- package/signals/implementation/signal.js +29 -49
- package/signals/implementation/to-observable.d.ts +12 -5
- package/signals/implementation/to-observable.js +12 -2
- package/signals/implementation/to-signal.d.ts +9 -18
- package/signals/implementation/to-signal.js +46 -13
- package/signals/implementation/untracked.d.ts +1 -1
- package/signals/implementation/untracked.js +3 -11
- package/signals/operators/debounce.d.ts +8 -0
- package/signals/operators/debounce.js +19 -0
- package/signals/operators/derive-async.js +43 -15
- package/signals/operators/index.d.ts +2 -0
- package/signals/operators/index.js +2 -0
- package/signals/operators/throttle.d.ts +8 -0
- package/signals/operators/throttle.js +31 -0
- package/ai/genkit/tests/multi-region.test.d.ts +0 -2
- package/ai/genkit/tests/multi-region.test.js +0 -179
- package/ai/genkit/tests/token-limit-fallback.test.d.ts +0 -2
- package/ai/genkit/tests/token-limit-fallback.test.js +0 -209
- package/ai/prompts/tests/prompt-builder.test.d.ts +0 -1
- package/ai/prompts/tests/prompt-builder.test.js +0 -22
- package/ai/tests/instructions-formatter.test.d.ts +0 -1
- package/ai/tests/instructions-formatter.test.js +0 -116
- package/ai/tests/steering.test.d.ts +0 -1
- package/ai/tests/steering.test.js +0 -37
- package/api/client/tests/api-client.test.d.ts +0 -1
- package/api/client/tests/api-client.test.js +0 -194
- package/api/server/tests/csrf.middleware.test.d.ts +0 -1
- package/api/server/tests/csrf.middleware.test.js +0 -91
- package/authentication/tests/authentication-password-requirements.validator.test.d.ts +0 -1
- package/authentication/tests/authentication-password-requirements.validator.test.js +0 -29
- package/authentication/tests/authentication.api-controller.test.d.ts +0 -1
- package/authentication/tests/authentication.api-controller.test.js +0 -156
- package/authentication/tests/authentication.api-request-token.provider.test.d.ts +0 -1
- package/authentication/tests/authentication.api-request-token.provider.test.js +0 -48
- package/authentication/tests/authentication.client-error-handling.test.d.ts +0 -1
- package/authentication/tests/authentication.client-error-handling.test.js +0 -123
- package/authentication/tests/authentication.client-middleware.test.d.ts +0 -1
- package/authentication/tests/authentication.client-middleware.test.js +0 -118
- package/authentication/tests/authentication.client-service-methods.test.d.ts +0 -1
- package/authentication/tests/authentication.client-service-methods.test.js +0 -177
- package/authentication/tests/authentication.client-service-refresh.test.d.ts +0 -1
- package/authentication/tests/authentication.client-service-refresh.test.js +0 -153
- package/authentication/tests/authentication.client-service.test.d.ts +0 -1
- package/authentication/tests/authentication.client-service.test.js +0 -76
- package/authentication/tests/authentication.refresh-busy-loop.test.d.ts +0 -1
- package/authentication/tests/authentication.refresh-busy-loop.test.js +0 -84
- package/authentication/tests/authentication.service.test.d.ts +0 -1
- package/authentication/tests/authentication.service.test.js +0 -167
- package/authentication/tests/authentication.test-ancillary-service.d.ts +0 -9
- package/authentication/tests/authentication.test-ancillary-service.js +0 -27
- package/authentication/tests/brute-force-protection.test.d.ts +0 -1
- package/authentication/tests/brute-force-protection.test.js +0 -211
- package/authentication/tests/helper.test.d.ts +0 -1
- package/authentication/tests/helper.test.js +0 -122
- package/authentication/tests/password-requirements.error.test.d.ts +0 -1
- package/authentication/tests/password-requirements.error.test.js +0 -14
- package/authentication/tests/remember.api.test.d.ts +0 -1
- package/authentication/tests/remember.api.test.js +0 -117
- package/authentication/tests/remember.service.test.d.ts +0 -1
- package/authentication/tests/remember.service.test.js +0 -83
- package/authentication/tests/subject.service.test.d.ts +0 -1
- package/authentication/tests/subject.service.test.js +0 -140
- package/authentication/tests/suspended-subject.test.d.ts +0 -1
- package/authentication/tests/suspended-subject.test.js +0 -120
- package/authentication/tests/totp.enrollment.test.d.ts +0 -1
- package/authentication/tests/totp.enrollment.test.js +0 -123
- package/authentication/tests/totp.login.test.d.ts +0 -1
- package/authentication/tests/totp.login.test.js +0 -213
- package/authentication/tests/totp.recovery-codes.test.d.ts +0 -1
- package/authentication/tests/totp.recovery-codes.test.js +0 -97
- package/authentication/tests/totp.status.test.d.ts +0 -1
- package/authentication/tests/totp.status.test.js +0 -72
- package/cancellation/tests/coverage.test.d.ts +0 -1
- package/cancellation/tests/coverage.test.js +0 -49
- package/cancellation/tests/leak.test.d.ts +0 -1
- package/cancellation/tests/leak.test.js +0 -35
- package/cancellation/tests/token.test.d.ts +0 -1
- package/cancellation/tests/token.test.js +0 -136
- package/circuit-breaker/tests/circuit-breaker.test.d.ts +0 -1
- package/circuit-breaker/tests/circuit-breaker.test.js +0 -116
- package/cryptography/tests/cryptography.test.d.ts +0 -1
- package/cryptography/tests/cryptography.test.js +0 -175
- package/cryptography/tests/jwt.test.d.ts +0 -1
- package/cryptography/tests/jwt.test.js +0 -54
- package/cryptography/tests/modern.test.d.ts +0 -1
- package/cryptography/tests/modern.test.js +0 -105
- package/cryptography/tests/module.test.d.ts +0 -1
- package/cryptography/tests/module.test.js +0 -100
- package/cryptography/tests/totp.test.d.ts +0 -1
- package/cryptography/tests/totp.test.js +0 -108
- package/document-management/tests/ai-config-hierarchy.test.d.ts +0 -1
- package/document-management/tests/ai-config-hierarchy.test.js +0 -59
- package/document-management/tests/ai-config-integration.test.d.ts +0 -1
- package/document-management/tests/ai-config-integration.test.js +0 -125
- package/document-management/tests/ai-config-merge.test.d.ts +0 -1
- package/document-management/tests/ai-config-merge.test.js +0 -46
- package/document-management/tests/document-management-ai-overrides.test.d.ts +0 -1
- package/document-management/tests/document-management-ai-overrides.test.js +0 -63
- package/document-management/tests/document-management-core.test.d.ts +0 -1
- package/document-management/tests/document-management-core.test.js +0 -157
- package/document-management/tests/document-management.api.test.d.ts +0 -1
- package/document-management/tests/document-management.api.test.js +0 -101
- package/document-management/tests/document-statistics.service.test.d.ts +0 -1
- package/document-management/tests/document-statistics.service.test.js +0 -498
- package/document-management/tests/document-validation-ai-overrides.test.d.ts +0 -1
- package/document-management/tests/document-validation-ai-overrides.test.js +0 -87
- package/document-management/tests/document.service.test.d.ts +0 -1
- package/document-management/tests/document.service.test.js +0 -143
- package/document-management/tests/enum-helpers.test.d.ts +0 -1
- package/document-management/tests/enum-helpers.test.js +0 -452
- package/document-management/tests/helper.d.ts +0 -24
- package/document-management/tests/helper.js +0 -39
- package/errors/tests/format.test.d.ts +0 -1
- package/errors/tests/format.test.js +0 -84
- package/http/tests/server-timing.test.d.ts +0 -1
- package/http/tests/server-timing.test.js +0 -42
- package/injector/tests/advanced.test.d.ts +0 -1
- package/injector/tests/advanced.test.js +0 -116
- package/injector/tests/async-init.test.d.ts +0 -1
- package/injector/tests/async-init.test.js +0 -77
- package/injector/tests/basic.test.d.ts +0 -1
- package/injector/tests/basic.test.js +0 -114
- package/injector/tests/hierarchical.test.d.ts +0 -1
- package/injector/tests/hierarchical.test.js +0 -59
- package/injector/tests/leak.test.d.ts +0 -1
- package/injector/tests/leak.test.js +0 -45
- package/injector/tests/lifecycles.test.d.ts +0 -1
- package/injector/tests/lifecycles.test.js +0 -109
- package/logger/tests/pretty-print.test.d.ts +0 -1
- package/logger/tests/pretty-print.test.js +0 -60
- package/notification/tests/notification-api.test.d.ts +0 -1
- package/notification/tests/notification-api.test.js +0 -124
- package/notification/tests/notification-client.test.d.ts +0 -1
- package/notification/tests/notification-client.test.js +0 -101
- package/notification/tests/notification-flow.test.d.ts +0 -1
- package/notification/tests/notification-flow.test.js +0 -296
- package/notification/tests/notification-sse.service.test.d.ts +0 -1
- package/notification/tests/notification-sse.service.test.js +0 -43
- package/notification/tests/notification-type.service.test.d.ts +0 -1
- package/notification/tests/notification-type.service.test.js +0 -41
- package/object-storage/s3/tests/s3.object-storage.integration.test.d.ts +0 -1
- package/object-storage/s3/tests/s3.object-storage.integration.test.js +0 -303
- package/orm/tests/build-jsonb.test.d.ts +0 -1
- package/orm/tests/build-jsonb.test.js +0 -39
- package/orm/tests/data-types.test.d.ts +0 -1
- package/orm/tests/data-types.test.js +0 -39
- package/orm/tests/database-extension.test.d.ts +0 -1
- package/orm/tests/database-extension.test.js +0 -63
- package/orm/tests/database-migration.test.d.ts +0 -1
- package/orm/tests/database-migration.test.js +0 -83
- package/orm/tests/decorators.test.d.ts +0 -1
- package/orm/tests/decorators.test.js +0 -77
- package/orm/tests/encryption.test.d.ts +0 -1
- package/orm/tests/encryption.test.js +0 -31
- package/orm/tests/query-complex.test.d.ts +0 -1
- package/orm/tests/query-complex.test.js +0 -172
- package/orm/tests/query-converter-complex.test.d.ts +0 -1
- package/orm/tests/query-converter-complex.test.js +0 -131
- package/orm/tests/query-converter.test.d.ts +0 -1
- package/orm/tests/query-converter.test.js +0 -123
- package/orm/tests/repository-advanced.test.d.ts +0 -1
- package/orm/tests/repository-advanced.test.js +0 -189
- package/orm/tests/repository-attributes.test.d.ts +0 -1
- package/orm/tests/repository-attributes.test.js +0 -83
- package/orm/tests/repository-compound-primary-key.test.d.ts +0 -2
- package/orm/tests/repository-compound-primary-key.test.js +0 -226
- package/orm/tests/repository-comprehensive.test.d.ts +0 -1
- package/orm/tests/repository-comprehensive.test.js +0 -162
- package/orm/tests/repository-coverage.test.d.ts +0 -2
- package/orm/tests/repository-coverage.test.js +0 -242
- package/orm/tests/repository-cti-complex.test.d.ts +0 -1
- package/orm/tests/repository-cti-complex.test.js +0 -151
- package/orm/tests/repository-cti-embedded.test.d.ts +0 -1
- package/orm/tests/repository-cti-embedded.test.js +0 -178
- package/orm/tests/repository-cti-extensive.test.d.ts +0 -2
- package/orm/tests/repository-cti-extensive.test.js +0 -279
- package/orm/tests/repository-cti-mapping.test.d.ts +0 -2
- package/orm/tests/repository-cti-mapping.test.js +0 -108
- package/orm/tests/repository-cti-search.test.d.ts +0 -1
- package/orm/tests/repository-cti-search.test.js +0 -141
- package/orm/tests/repository-cti-soft-delete.test.d.ts +0 -2
- package/orm/tests/repository-cti-soft-delete.test.js +0 -103
- package/orm/tests/repository-cti-transactions.test.d.ts +0 -1
- package/orm/tests/repository-cti-transactions.test.js +0 -112
- package/orm/tests/repository-cti-upsert-many.test.d.ts +0 -2
- package/orm/tests/repository-cti-upsert-many.test.js +0 -115
- package/orm/tests/repository-cti.test.d.ts +0 -2
- package/orm/tests/repository-cti.test.js +0 -390
- package/orm/tests/repository-edge-cases.test.d.ts +0 -1
- package/orm/tests/repository-edge-cases.test.js +0 -178
- package/orm/tests/repository-expiration.test.d.ts +0 -2
- package/orm/tests/repository-expiration.test.js +0 -140
- package/orm/tests/repository-extra-coverage.test.d.ts +0 -2
- package/orm/tests/repository-extra-coverage.test.js +0 -402
- package/orm/tests/repository-mapping.test.d.ts +0 -2
- package/orm/tests/repository-mapping.test.js +0 -65
- package/orm/tests/repository-regression.test.d.ts +0 -1
- package/orm/tests/repository-regression.test.js +0 -288
- package/orm/tests/repository-search-coverage.test.d.ts +0 -1
- package/orm/tests/repository-search-coverage.test.js +0 -107
- package/orm/tests/repository-search.test.d.ts +0 -1
- package/orm/tests/repository-search.test.js +0 -105
- package/orm/tests/repository-soft-delete.test.d.ts +0 -1
- package/orm/tests/repository-soft-delete.test.js +0 -118
- package/orm/tests/repository-transactions-nested.test.d.ts +0 -1
- package/orm/tests/repository-transactions-nested.test.js +0 -178
- package/orm/tests/repository-types.test.d.ts +0 -1
- package/orm/tests/repository-types.test.js +0 -184
- package/orm/tests/repository-undelete.test.d.ts +0 -2
- package/orm/tests/repository-undelete.test.js +0 -201
- package/orm/tests/schema-converter.test.d.ts +0 -1
- package/orm/tests/schema-converter.test.js +0 -82
- package/orm/tests/schema-generation.test.d.ts +0 -2
- package/orm/tests/schema-generation.test.js +0 -174
- package/orm/tests/sql-helpers.test.d.ts +0 -1
- package/orm/tests/sql-helpers.test.js +0 -67
- package/orm/tests/transaction-safety.test.d.ts +0 -1
- package/orm/tests/transaction-safety.test.js +0 -81
- package/orm/tests/transactional.test.d.ts +0 -1
- package/orm/tests/transactional.test.js +0 -215
- package/orm/tests/utils.test.d.ts +0 -1
- package/orm/tests/utils.test.js +0 -70
- package/pdf/tests/utils.test.d.ts +0 -1
- package/pdf/tests/utils.test.js +0 -187
- package/process/tests/spawn.test.d.ts +0 -1
- package/process/tests/spawn.test.js +0 -182
- package/rate-limit/tests/postgres-rate-limiter.test.d.ts +0 -1
- package/rate-limit/tests/postgres-rate-limiter.test.js +0 -84
- package/renderer/tests/renderer.test.d.ts +0 -1
- package/renderer/tests/renderer.test.js +0 -88
- package/rpc/tests/rpc.integration.test.d.ts +0 -1
- package/rpc/tests/rpc.integration.test.js +0 -615
- package/signals/implementation/errors.d.ts +0 -2
- package/signals/implementation/graph.js +0 -312
- package/signals/implementation/writable-signal.d.ts +0 -48
- package/signals/implementation/writable-signal.js +0 -32
- package/task-queue/tests/coverage-branch.test.d.ts +0 -1
- package/task-queue/tests/coverage-branch.test.js +0 -395
- package/task-queue/tests/coverage-enhancement.test.d.ts +0 -1
- package/task-queue/tests/coverage-enhancement.test.js +0 -150
- package/task-queue/tests/dag.test.d.ts +0 -1
- package/task-queue/tests/dag.test.js +0 -188
- package/task-queue/tests/dependencies.test.d.ts +0 -1
- package/task-queue/tests/dependencies.test.js +0 -296
- package/task-queue/tests/enqueue-batch.test.d.ts +0 -1
- package/task-queue/tests/enqueue-batch.test.js +0 -125
- package/task-queue/tests/enqueue-item.test.d.ts +0 -1
- package/task-queue/tests/enqueue-item.test.js +0 -12
- package/task-queue/tests/fan-out-spawning.test.d.ts +0 -1
- package/task-queue/tests/fan-out-spawning.test.js +0 -94
- package/task-queue/tests/idempotent-replacement.test.d.ts +0 -1
- package/task-queue/tests/idempotent-replacement.test.js +0 -114
- package/task-queue/tests/missing-idempotent-tasks.test.d.ts +0 -1
- package/task-queue/tests/missing-idempotent-tasks.test.js +0 -39
- package/task-queue/tests/optimization-edge-cases.test.d.ts +0 -1
- package/task-queue/tests/optimization-edge-cases.test.js +0 -124
- package/task-queue/tests/queue-generic.test.d.ts +0 -1
- package/task-queue/tests/queue-generic.test.js +0 -8
- package/task-queue/tests/queue.test.d.ts +0 -1
- package/task-queue/tests/queue.test.js +0 -756
- package/task-queue/tests/shutdown.test.d.ts +0 -1
- package/task-queue/tests/shutdown.test.js +0 -41
- package/task-queue/tests/task-context.test.d.ts +0 -1
- package/task-queue/tests/task-context.test.js +0 -7
- package/task-queue/tests/task-union.test.d.ts +0 -1
- package/task-queue/tests/task-union.test.js +0 -18
- package/task-queue/tests/transactions.test.d.ts +0 -1
- package/task-queue/tests/transactions.test.js +0 -47
- package/task-queue/tests/typing.test.d.ts +0 -1
- package/task-queue/tests/typing.test.js +0 -9
- package/task-queue/tests/worker.test.d.ts +0 -1
- package/task-queue/tests/worker.test.js +0 -258
- package/task-queue/tests/zombie-parent.test.d.ts +0 -1
- package/task-queue/tests/zombie-parent.test.js +0 -45
- package/task-queue/tests/zombie-recovery.test.d.ts +0 -1
- package/task-queue/tests/zombie-recovery.test.js +0 -51
- package/utils/tests/backoff.test.d.ts +0 -1
- package/utils/tests/backoff.test.js +0 -41
- package/utils/tests/retry-with-backoff.test.d.ts +0 -1
- package/utils/tests/retry-with-backoff.test.js +0 -49
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { SIGNAL } from './graph.js';
|
|
9
|
+
/**
|
|
10
|
+
* A custom formatter which renders signals in an easy-to-read format.
|
|
11
|
+
*
|
|
12
|
+
* @see https://firefox-source-docs.mozilla.org/devtools-user/custom_formatters/index.html
|
|
13
|
+
*/
|
|
14
|
+
const formatter = {
|
|
15
|
+
/**
|
|
16
|
+
* If the function returns `null`, the formatter is not used for this reference
|
|
17
|
+
*/
|
|
18
|
+
header: (sig, config) => {
|
|
19
|
+
if (!isSignal(sig) || config?.ngSkipFormatting)
|
|
20
|
+
return null;
|
|
21
|
+
let value;
|
|
22
|
+
try {
|
|
23
|
+
value = sig();
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
// In case the signal throws, we don't want to break the formatting.
|
|
27
|
+
return ['span', `Signal(⚠️ Error)${e.message ? `: ${e.message}` : ''}`];
|
|
28
|
+
}
|
|
29
|
+
const kind = 'computation' in sig[SIGNAL] ? 'Computed' : 'Signal';
|
|
30
|
+
const isPrimitive = value === null || (!Array.isArray(value) && typeof value !== 'object');
|
|
31
|
+
return [
|
|
32
|
+
'span',
|
|
33
|
+
{},
|
|
34
|
+
['span', {}, `${kind}(`],
|
|
35
|
+
(() => {
|
|
36
|
+
if (isSignal(value)) {
|
|
37
|
+
// Recursively call formatter. Could return an `object` to call the formatter through DevTools,
|
|
38
|
+
// but then recursive signals will render multiple expando arrows which is an awkward UX.
|
|
39
|
+
return formatter.header(value, config);
|
|
40
|
+
}
|
|
41
|
+
else if (isPrimitive && value !== undefined && typeof value !== 'function') {
|
|
42
|
+
// Use built-in rendering for primitives which applies standard syntax highlighting / theming.
|
|
43
|
+
// Can't do this for `undefined` however, as the browser thinks we forgot to provide an object.
|
|
44
|
+
// Also don't want to do this for functions which render nested expando arrows.
|
|
45
|
+
return ['object', { object: value }];
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return prettifyPreview(value);
|
|
49
|
+
}
|
|
50
|
+
})(),
|
|
51
|
+
['span', {}, `)`],
|
|
52
|
+
];
|
|
53
|
+
},
|
|
54
|
+
hasBody: (sig, config) => {
|
|
55
|
+
if (!isSignal(sig))
|
|
56
|
+
return false;
|
|
57
|
+
try {
|
|
58
|
+
sig();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return !config?.ngSkipFormatting;
|
|
64
|
+
},
|
|
65
|
+
body: (sig, config) => {
|
|
66
|
+
// We can use sys colors to fit the current DevTools theme.
|
|
67
|
+
// Those are unfortunately only available on Chromium-based browsers.
|
|
68
|
+
// On Firefow we fall back to the default color
|
|
69
|
+
const color = 'var(--sys-color-primary)';
|
|
70
|
+
return [
|
|
71
|
+
'div',
|
|
72
|
+
{ style: `background: #FFFFFF10; padding-left: 4px; padding-top: 2px; padding-bottom: 2px;` },
|
|
73
|
+
['div', { style: `color: ${color}` }, 'Signal value: '],
|
|
74
|
+
['div', { style: `padding-left: .5rem;` }, ['object', { object: sig(), config }]],
|
|
75
|
+
['div', { style: `color: ${color}` }, 'Signal function: '],
|
|
76
|
+
[
|
|
77
|
+
'div',
|
|
78
|
+
{ style: `padding-left: .5rem;` },
|
|
79
|
+
['object', { object: sig, config: { ...config, ngSkipFormatting: true } }],
|
|
80
|
+
],
|
|
81
|
+
];
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
function prettifyPreview(value) {
|
|
85
|
+
if (value === null)
|
|
86
|
+
return 'null';
|
|
87
|
+
if (Array.isArray(value))
|
|
88
|
+
return `Array(${value.length})`;
|
|
89
|
+
if (value instanceof Element)
|
|
90
|
+
return `<${value.tagName.toLowerCase()}>`;
|
|
91
|
+
if (value instanceof URL)
|
|
92
|
+
return `URL`;
|
|
93
|
+
switch (typeof value) {
|
|
94
|
+
case 'undefined': {
|
|
95
|
+
return 'undefined';
|
|
96
|
+
}
|
|
97
|
+
case 'function': {
|
|
98
|
+
if ('prototype' in value) {
|
|
99
|
+
// This is what Chrome renders, can't use `object` though because it creates a nested expando arrow.
|
|
100
|
+
return 'class';
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return '() => {…}';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
case 'object': {
|
|
107
|
+
if (value.constructor.name === 'Object') {
|
|
108
|
+
return '{…}';
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
return `${value.constructor.name} {}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
default: {
|
|
115
|
+
return ['object', { object: value, config: { ngSkipFormatting: true } }];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function isSignal(value) {
|
|
120
|
+
return value[SIGNAL] !== undefined;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Installs the custom formatter into custom formatting on Signals in the devtools.
|
|
124
|
+
*
|
|
125
|
+
* Supported by both Chrome and Firefox.
|
|
126
|
+
*
|
|
127
|
+
* @see https://firefox-source-docs.mozilla.org/devtools-user/custom_formatters/index.html
|
|
128
|
+
*/
|
|
129
|
+
export function installDevToolsSignalFormatter() {
|
|
130
|
+
globalThis.devtoolsFormatters ??= [];
|
|
131
|
+
if (!globalThis.devtoolsFormatters.some((f) => f === formatter)) {
|
|
132
|
+
globalThis.devtoolsFormatters.push(formatter);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// This fixes the RollupError: Exported variable "global" is not defined.
|
|
136
|
+
export {};
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { SIGNAL } from '../../symbol.js';
|
|
2
9
|
export { SIGNAL };
|
|
3
|
-
type Version = number & {
|
|
10
|
+
export type Version = number & {
|
|
4
11
|
__brand: 'Version';
|
|
5
12
|
};
|
|
13
|
+
export type ReactiveHookFn = (node: ReactiveNode) => void;
|
|
6
14
|
export declare function setActiveConsumer(consumer: ReactiveNode | null): ReactiveNode | null;
|
|
7
15
|
export declare function getActiveConsumer(): ReactiveNode | null;
|
|
8
16
|
export declare function isInNotificationPhase(): boolean;
|
|
@@ -11,6 +19,15 @@ export interface Reactive {
|
|
|
11
19
|
}
|
|
12
20
|
export declare function isReactive(value: unknown): value is Reactive;
|
|
13
21
|
export declare const REACTIVE_NODE: ReactiveNode;
|
|
22
|
+
interface ReactiveLink {
|
|
23
|
+
producer: ReactiveNode;
|
|
24
|
+
consumer: ReactiveNode;
|
|
25
|
+
lastReadVersion: number;
|
|
26
|
+
prevConsumer: ReactiveLink | undefined;
|
|
27
|
+
nextConsumer: ReactiveLink | undefined;
|
|
28
|
+
nextProducer: ReactiveLink | undefined;
|
|
29
|
+
}
|
|
30
|
+
export type ReactiveNodeKind = 'signal' | 'computed' | 'effect' | 'template' | 'linkedSignal' | 'afterRenderEffectPhase' | 'unknown';
|
|
14
31
|
/**
|
|
15
32
|
* A producer and/or consumer which participates in the reactive graph.
|
|
16
33
|
*
|
|
@@ -46,47 +63,26 @@ export interface ReactiveNode {
|
|
|
46
63
|
*/
|
|
47
64
|
dirty: boolean;
|
|
48
65
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* Uses the same indices as the `producerLastReadVersion` and `producerIndexOfThis` arrays.
|
|
52
|
-
*/
|
|
53
|
-
producerNode: ReactiveNode[] | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* `Version` of the value last read by a given producer.
|
|
56
|
-
*
|
|
57
|
-
* Uses the same indices as the `producerNode` and `producerIndexOfThis` arrays.
|
|
58
|
-
*/
|
|
59
|
-
producerLastReadVersion: Version[] | undefined;
|
|
60
|
-
/**
|
|
61
|
-
* Index of `this` (consumer) in each producer's `liveConsumers` array.
|
|
62
|
-
*
|
|
63
|
-
* This value is only meaningful if this node is live (`liveConsumers.length > 0`). Otherwise
|
|
64
|
-
* these indices are stale.
|
|
65
|
-
*
|
|
66
|
-
* Uses the same indices as the `producerNode` and `producerLastReadVersion` arrays.
|
|
66
|
+
* Whether this node is currently rebuilding its producer list.
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
recomputing: boolean;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* This index is zeroed before this node as a consumer begins executing. When a producer is read,
|
|
73
|
-
* it gets inserted into the producers arrays at this index. There may be an existing dependency
|
|
74
|
-
* in this location which may or may not match the incoming producer, depending on whether the
|
|
75
|
-
* same producers were read in the same order as the last computation.
|
|
70
|
+
* Producers which are dependencies of this consumer.
|
|
76
71
|
*/
|
|
77
|
-
|
|
72
|
+
producers: ReactiveLink | undefined;
|
|
78
73
|
/**
|
|
79
|
-
*
|
|
74
|
+
* Points to the last linked list node in the `producers` linked list.
|
|
80
75
|
*
|
|
81
|
-
*
|
|
76
|
+
* When this node is recomputing, this is used to track the producers that we have accessed so far.
|
|
82
77
|
*/
|
|
83
|
-
|
|
78
|
+
producersTail: ReactiveLink | undefined;
|
|
84
79
|
/**
|
|
85
|
-
*
|
|
80
|
+
* Linked list of consumers of this producer that are "live" (they require push notifications).
|
|
86
81
|
*
|
|
87
|
-
*
|
|
82
|
+
* The length of this list is effectively our reference count for this node.
|
|
88
83
|
*/
|
|
89
|
-
|
|
84
|
+
consumers: ReactiveLink | undefined;
|
|
85
|
+
consumersTail: ReactiveLink | undefined;
|
|
90
86
|
/**
|
|
91
87
|
* Whether writes to signals are allowed when this consumer is the `activeConsumer`.
|
|
92
88
|
*
|
|
@@ -106,6 +102,19 @@ export interface ReactiveNode {
|
|
|
106
102
|
* Called when a signal is read within this consumer.
|
|
107
103
|
*/
|
|
108
104
|
consumerOnSignalRead(node: unknown): void;
|
|
105
|
+
/**
|
|
106
|
+
* A debug name for the reactive node. Used in Angular DevTools to identify the node.
|
|
107
|
+
*/
|
|
108
|
+
debugName?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Kind of node. Example: 'signal', 'computed', 'input', 'effect'.
|
|
111
|
+
*
|
|
112
|
+
* ReactiveNode has this as 'unknown' by default, but derived node types should override this to
|
|
113
|
+
* make available the kind of signal that particular instance of a ReactiveNode represents.
|
|
114
|
+
*
|
|
115
|
+
* Used in Angular DevTools to identify the kind of signal.
|
|
116
|
+
*/
|
|
117
|
+
kind: ReactiveNodeKind;
|
|
109
118
|
}
|
|
110
119
|
/**
|
|
111
120
|
* Called by implementations when a producer's signal is read.
|
|
@@ -131,20 +140,41 @@ export declare function producerNotifyConsumers(node: ReactiveNode): void;
|
|
|
131
140
|
*/
|
|
132
141
|
export declare function producerUpdatesAllowed(): boolean;
|
|
133
142
|
export declare function consumerMarkDirty(node: ReactiveNode): void;
|
|
143
|
+
export declare function producerMarkClean(node: ReactiveNode): void;
|
|
134
144
|
/**
|
|
135
|
-
* Prepare this consumer to run a computation in its reactive context
|
|
145
|
+
* Prepare this consumer to run a computation in its reactive context and set
|
|
146
|
+
* it as the active consumer.
|
|
136
147
|
*
|
|
137
148
|
* Must be called by subclasses which represent reactive computations, before those computations
|
|
138
149
|
* begin.
|
|
139
150
|
*/
|
|
140
151
|
export declare function consumerBeforeComputation(node: ReactiveNode | null): ReactiveNode | null;
|
|
141
152
|
/**
|
|
142
|
-
*
|
|
153
|
+
* Prepare this consumer to run a computation in its reactive context.
|
|
154
|
+
*
|
|
155
|
+
* We expose this mainly for code where we manually batch effects into a single
|
|
156
|
+
* consumer. In those cases we may wish to "reopen" a consumer multiple times
|
|
157
|
+
* in initial render before finalizing it. Most code should just call
|
|
158
|
+
* `consumerBeforeComputation` instead of calling this directly.
|
|
159
|
+
*/
|
|
160
|
+
export declare function resetConsumerBeforeComputation(node: ReactiveNode): void;
|
|
161
|
+
/**
|
|
162
|
+
* Finalize this consumer's state and set previous consumer as the active consumer after a
|
|
163
|
+
* reactive computation has run.
|
|
143
164
|
*
|
|
144
165
|
* Must be called by subclasses which represent reactive computations, after those computations
|
|
145
166
|
* have finished.
|
|
146
167
|
*/
|
|
147
168
|
export declare function consumerAfterComputation(node: ReactiveNode | null, prevConsumer: ReactiveNode | null): void;
|
|
169
|
+
/**
|
|
170
|
+
* Finalize this consumer's state after a reactive computation has run.
|
|
171
|
+
*
|
|
172
|
+
* We expose this mainly for code where we manually batch effects into a single
|
|
173
|
+
* consumer. In those cases we may wish to "reopen" a consumer multiple times
|
|
174
|
+
* in initial render before finalizing it. Most code should just call
|
|
175
|
+
* `consumerAfterComputation` instead of calling this directly.
|
|
176
|
+
*/
|
|
177
|
+
export declare function finalizeConsumerAfterComputation(node: ReactiveNode): void;
|
|
148
178
|
/**
|
|
149
179
|
* Determine whether this consumer has any dependencies which have changed since the last time
|
|
150
180
|
* they were read.
|
|
@@ -154,3 +184,5 @@ export declare function consumerPollProducersForChange(node: ReactiveNode): bool
|
|
|
154
184
|
* Disconnect this consumer from the graph.
|
|
155
185
|
*/
|
|
156
186
|
export declare function consumerDestroy(node: ReactiveNode): void;
|
|
187
|
+
export declare function runPostProducerCreatedFn(node: ReactiveNode): void;
|
|
188
|
+
export declare function setPostProducerCreatedFn(fn: ReactiveHookFn | null): ReactiveHookFn | null;
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { isDevMode } from '../../../core.js';
|
|
9
|
+
import { SIGNAL } from '../../symbol.js';
|
|
10
|
+
export { SIGNAL };
|
|
11
|
+
/**
|
|
12
|
+
* The currently active consumer `ReactiveNode`, if running code in a reactive context.
|
|
13
|
+
*
|
|
14
|
+
* Change this via `setActiveConsumer`.
|
|
15
|
+
*/
|
|
16
|
+
let activeConsumer = null;
|
|
17
|
+
let inNotificationPhase = false;
|
|
18
|
+
/**
|
|
19
|
+
* Global epoch counter. Incremented whenever a source signal is set.
|
|
20
|
+
*/
|
|
21
|
+
let epoch = 1;
|
|
22
|
+
/**
|
|
23
|
+
* If set, called after a producer `ReactiveNode` is created.
|
|
24
|
+
*/
|
|
25
|
+
let postProducerCreatedFn = null;
|
|
26
|
+
export function setActiveConsumer(consumer) {
|
|
27
|
+
const prev = activeConsumer;
|
|
28
|
+
activeConsumer = consumer;
|
|
29
|
+
return prev;
|
|
30
|
+
}
|
|
31
|
+
export function getActiveConsumer() {
|
|
32
|
+
return activeConsumer;
|
|
33
|
+
}
|
|
34
|
+
export function isInNotificationPhase() {
|
|
35
|
+
return inNotificationPhase;
|
|
36
|
+
}
|
|
37
|
+
export function isReactive(value) {
|
|
38
|
+
return value[SIGNAL] !== undefined;
|
|
39
|
+
}
|
|
40
|
+
export const REACTIVE_NODE = {
|
|
41
|
+
version: 0,
|
|
42
|
+
lastCleanEpoch: 0,
|
|
43
|
+
dirty: false,
|
|
44
|
+
producers: undefined,
|
|
45
|
+
producersTail: undefined,
|
|
46
|
+
consumers: undefined,
|
|
47
|
+
consumersTail: undefined,
|
|
48
|
+
recomputing: false,
|
|
49
|
+
consumerAllowSignalWrites: false,
|
|
50
|
+
consumerIsAlwaysLive: false,
|
|
51
|
+
kind: 'unknown',
|
|
52
|
+
producerMustRecompute: () => false,
|
|
53
|
+
producerRecomputeValue: () => { },
|
|
54
|
+
consumerMarkedDirty: () => { },
|
|
55
|
+
consumerOnSignalRead: () => { },
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Called by implementations when a producer's signal is read.
|
|
59
|
+
*/
|
|
60
|
+
export function producerAccessed(node) {
|
|
61
|
+
if (inNotificationPhase) {
|
|
62
|
+
throw new Error(isDevMode()
|
|
63
|
+
? `Assertion error: signal read during notification phase`
|
|
64
|
+
: '');
|
|
65
|
+
}
|
|
66
|
+
if (activeConsumer === null) {
|
|
67
|
+
// Accessed outside of a reactive context, so nothing to record.
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
activeConsumer.consumerOnSignalRead(node);
|
|
71
|
+
const prevProducerLink = activeConsumer.producersTail;
|
|
72
|
+
// If the last producer we accessed is the same as the current one, we can skip adding a new
|
|
73
|
+
// link
|
|
74
|
+
if (prevProducerLink !== undefined && prevProducerLink.producer === node) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
let nextProducerLink = undefined;
|
|
78
|
+
const isRecomputing = activeConsumer.recomputing;
|
|
79
|
+
if (isRecomputing) {
|
|
80
|
+
// If we're incrementally rebuilding the producers list, we want to check if the next producer
|
|
81
|
+
// in the list is the same as the one we're trying to add.
|
|
82
|
+
// If the previous producer is defined, then the next producer is just the one that follows it.
|
|
83
|
+
// Otherwise, we should check the head of the producers list (the first node that we accessed the last time this consumer was run).
|
|
84
|
+
nextProducerLink =
|
|
85
|
+
prevProducerLink !== undefined ? prevProducerLink.nextProducer : activeConsumer.producers;
|
|
86
|
+
if (nextProducerLink !== undefined && nextProducerLink.producer === node) {
|
|
87
|
+
// If the next producer is the same as the one we're trying to add, we can just update the
|
|
88
|
+
// last read version, update the tail of the producers list of this rerun, and return.
|
|
89
|
+
activeConsumer.producersTail = nextProducerLink;
|
|
90
|
+
nextProducerLink.lastReadVersion = node.version;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const prevConsumerLink = node.consumersTail;
|
|
95
|
+
// If the producer we're accessing already has a link to this consumer, we can skip adding a new
|
|
96
|
+
// link. This can short circuit the creation of a new link in the case where the consumer reads alternating ReeactiveNodes
|
|
97
|
+
if (prevConsumerLink !== undefined &&
|
|
98
|
+
prevConsumerLink.consumer === activeConsumer &&
|
|
99
|
+
// However, we have to make sure that the link we've discovered isn't from a node that is incrementally rebuilding its producer list
|
|
100
|
+
(!isRecomputing || isValidLink(prevConsumerLink, activeConsumer))) {
|
|
101
|
+
// If we found an existing link to the consumer we can just return.
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// If we got here, it means that we need to create a new link between the producer and the consumer.
|
|
105
|
+
const isLive = consumerIsLive(activeConsumer);
|
|
106
|
+
const newLink = {
|
|
107
|
+
producer: node,
|
|
108
|
+
consumer: activeConsumer,
|
|
109
|
+
// instead of eagerly destroying the previous link, we delay until we've finished recomputing
|
|
110
|
+
// the producers list, so that we can destroy all of the old links at once.
|
|
111
|
+
nextProducer: nextProducerLink,
|
|
112
|
+
prevConsumer: prevConsumerLink,
|
|
113
|
+
lastReadVersion: node.version,
|
|
114
|
+
nextConsumer: undefined,
|
|
115
|
+
};
|
|
116
|
+
activeConsumer.producersTail = newLink;
|
|
117
|
+
if (prevProducerLink !== undefined) {
|
|
118
|
+
prevProducerLink.nextProducer = newLink;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
activeConsumer.producers = newLink;
|
|
122
|
+
}
|
|
123
|
+
if (isLive) {
|
|
124
|
+
producerAddLiveConsumer(node, newLink);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Increment the global epoch counter.
|
|
129
|
+
*
|
|
130
|
+
* Called by source producers (that is, not computeds) whenever their values change.
|
|
131
|
+
*/
|
|
132
|
+
export function producerIncrementEpoch() {
|
|
133
|
+
epoch++;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Ensure this producer's `version` is up-to-date.
|
|
137
|
+
*/
|
|
138
|
+
export function producerUpdateValueVersion(node) {
|
|
139
|
+
if (consumerIsLive(node) && !node.dirty) {
|
|
140
|
+
// A live consumer will be marked dirty by producers, so a clean state means that its version
|
|
141
|
+
// is guaranteed to be up-to-date.
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!node.dirty && node.lastCleanEpoch === epoch) {
|
|
145
|
+
// Even non-live consumers can skip polling if they previously found themselves to be clean at
|
|
146
|
+
// the current epoch, since their dependencies could not possibly have changed (such a change
|
|
147
|
+
// would've increased the epoch).
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (!node.producerMustRecompute(node) && !consumerPollProducersForChange(node)) {
|
|
151
|
+
// None of our producers report a change since the last time they were read, so no
|
|
152
|
+
// recomputation of our value is necessary, and we can consider ourselves clean.
|
|
153
|
+
producerMarkClean(node);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
node.producerRecomputeValue(node);
|
|
157
|
+
// After recomputing the value, we're no longer dirty.
|
|
158
|
+
producerMarkClean(node);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Propagate a dirty notification to live consumers of this producer.
|
|
162
|
+
*/
|
|
163
|
+
export function producerNotifyConsumers(node) {
|
|
164
|
+
if (node.consumers === undefined) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
// Prevent signal reads when we're updating the graph
|
|
168
|
+
const prev = inNotificationPhase;
|
|
169
|
+
inNotificationPhase = true;
|
|
170
|
+
try {
|
|
171
|
+
for (let link = node.consumers; link !== undefined; link = link.nextConsumer) {
|
|
172
|
+
const consumer = link.consumer;
|
|
173
|
+
if (!consumer.dirty) {
|
|
174
|
+
consumerMarkDirty(consumer);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
inNotificationPhase = prev;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Whether this `ReactiveNode` in its producer capacity is currently allowed to initiate updates,
|
|
184
|
+
* based on the current consumer context.
|
|
185
|
+
*/
|
|
186
|
+
export function producerUpdatesAllowed() {
|
|
187
|
+
return activeConsumer?.consumerAllowSignalWrites !== false;
|
|
188
|
+
}
|
|
189
|
+
export function consumerMarkDirty(node) {
|
|
190
|
+
node.dirty = true;
|
|
191
|
+
producerNotifyConsumers(node);
|
|
192
|
+
node.consumerMarkedDirty?.(node);
|
|
193
|
+
}
|
|
194
|
+
export function producerMarkClean(node) {
|
|
195
|
+
node.dirty = false;
|
|
196
|
+
node.lastCleanEpoch = epoch;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Prepare this consumer to run a computation in its reactive context and set
|
|
200
|
+
* it as the active consumer.
|
|
201
|
+
*
|
|
202
|
+
* Must be called by subclasses which represent reactive computations, before those computations
|
|
203
|
+
* begin.
|
|
204
|
+
*/
|
|
205
|
+
export function consumerBeforeComputation(node) {
|
|
206
|
+
if (node)
|
|
207
|
+
resetConsumerBeforeComputation(node);
|
|
208
|
+
return setActiveConsumer(node);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Prepare this consumer to run a computation in its reactive context.
|
|
212
|
+
*
|
|
213
|
+
* We expose this mainly for code where we manually batch effects into a single
|
|
214
|
+
* consumer. In those cases we may wish to "reopen" a consumer multiple times
|
|
215
|
+
* in initial render before finalizing it. Most code should just call
|
|
216
|
+
* `consumerBeforeComputation` instead of calling this directly.
|
|
217
|
+
*/
|
|
218
|
+
export function resetConsumerBeforeComputation(node) {
|
|
219
|
+
node.producersTail = undefined;
|
|
220
|
+
node.recomputing = true;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Finalize this consumer's state and set previous consumer as the active consumer after a
|
|
224
|
+
* reactive computation has run.
|
|
225
|
+
*
|
|
226
|
+
* Must be called by subclasses which represent reactive computations, after those computations
|
|
227
|
+
* have finished.
|
|
228
|
+
*/
|
|
229
|
+
export function consumerAfterComputation(node, prevConsumer) {
|
|
230
|
+
setActiveConsumer(prevConsumer);
|
|
231
|
+
if (node)
|
|
232
|
+
finalizeConsumerAfterComputation(node);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Finalize this consumer's state after a reactive computation has run.
|
|
236
|
+
*
|
|
237
|
+
* We expose this mainly for code where we manually batch effects into a single
|
|
238
|
+
* consumer. In those cases we may wish to "reopen" a consumer multiple times
|
|
239
|
+
* in initial render before finalizing it. Most code should just call
|
|
240
|
+
* `consumerAfterComputation` instead of calling this directly.
|
|
241
|
+
*/
|
|
242
|
+
export function finalizeConsumerAfterComputation(node) {
|
|
243
|
+
node.recomputing = false;
|
|
244
|
+
// We've finished incrementally rebuilding the producers list, now if there are any producers
|
|
245
|
+
// that are after producersTail, they are stale and should be removed.
|
|
246
|
+
const producersTail = node.producersTail;
|
|
247
|
+
let toRemove = producersTail !== undefined ? producersTail.nextProducer : node.producers;
|
|
248
|
+
if (toRemove !== undefined) {
|
|
249
|
+
if (consumerIsLive(node)) {
|
|
250
|
+
// For each stale link, we first unlink it from the producers list of consumers
|
|
251
|
+
do {
|
|
252
|
+
toRemove = producerRemoveLiveConsumerLink(toRemove);
|
|
253
|
+
} while (toRemove !== undefined);
|
|
254
|
+
}
|
|
255
|
+
// Now, we can truncate the producers list to remove all stale links.
|
|
256
|
+
if (producersTail !== undefined) {
|
|
257
|
+
producersTail.nextProducer = undefined;
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
node.producers = undefined;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Determine whether this consumer has any dependencies which have changed since the last time
|
|
266
|
+
* they were read.
|
|
267
|
+
*/
|
|
268
|
+
export function consumerPollProducersForChange(node) {
|
|
269
|
+
// Poll producers for change.
|
|
270
|
+
for (let link = node.producers; link !== undefined; link = link.nextProducer) {
|
|
271
|
+
const producer = link.producer;
|
|
272
|
+
const seenVersion = link.lastReadVersion;
|
|
273
|
+
// First check the versions. A mismatch means that the producer's value is known to have
|
|
274
|
+
// changed since the last time we read it.
|
|
275
|
+
if (seenVersion !== producer.version) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
// The producer's version is the same as the last time we read it, but it might itself be
|
|
279
|
+
// stale. Force the producer to recompute its version (calculating a new value if necessary).
|
|
280
|
+
producerUpdateValueVersion(producer);
|
|
281
|
+
// Now when we do this check, `producer.version` is guaranteed to be up to date, so if the
|
|
282
|
+
// versions still match then it has not changed since the last time we read it.
|
|
283
|
+
if (seenVersion !== producer.version) {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Disconnect this consumer from the graph.
|
|
291
|
+
*/
|
|
292
|
+
export function consumerDestroy(node) {
|
|
293
|
+
if (consumerIsLive(node)) {
|
|
294
|
+
// Drop all connections from the graph to this node.
|
|
295
|
+
let link = node.producers;
|
|
296
|
+
while (link !== undefined) {
|
|
297
|
+
link = producerRemoveLiveConsumerLink(link);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// Truncate all the linked lists to drop all connection from this node to the graph.
|
|
301
|
+
node.producers = undefined;
|
|
302
|
+
node.producersTail = undefined;
|
|
303
|
+
node.consumers = undefined;
|
|
304
|
+
node.consumersTail = undefined;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Add `consumer` as a live consumer of this node.
|
|
308
|
+
*
|
|
309
|
+
* Note that this operation is potentially transitive. If this node becomes live, then it becomes
|
|
310
|
+
* a live consumer of all of its current producers.
|
|
311
|
+
*/
|
|
312
|
+
function producerAddLiveConsumer(node, link) {
|
|
313
|
+
const consumersTail = node.consumersTail;
|
|
314
|
+
const wasLive = consumerIsLive(node);
|
|
315
|
+
if (consumersTail !== undefined) {
|
|
316
|
+
link.nextConsumer = consumersTail.nextConsumer;
|
|
317
|
+
consumersTail.nextConsumer = link;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
link.nextConsumer = undefined;
|
|
321
|
+
node.consumers = link;
|
|
322
|
+
}
|
|
323
|
+
link.prevConsumer = consumersTail;
|
|
324
|
+
node.consumersTail = link;
|
|
325
|
+
if (!wasLive) {
|
|
326
|
+
for (let link = node.producers; link !== undefined; link = link.nextProducer) {
|
|
327
|
+
producerAddLiveConsumer(link.producer, link);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function producerRemoveLiveConsumerLink(link) {
|
|
332
|
+
const producer = link.producer;
|
|
333
|
+
const nextProducer = link.nextProducer;
|
|
334
|
+
const nextConsumer = link.nextConsumer;
|
|
335
|
+
const prevConsumer = link.prevConsumer;
|
|
336
|
+
link.nextConsumer = undefined;
|
|
337
|
+
link.prevConsumer = undefined;
|
|
338
|
+
if (nextConsumer !== undefined) {
|
|
339
|
+
nextConsumer.prevConsumer = prevConsumer;
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
producer.consumersTail = prevConsumer;
|
|
343
|
+
}
|
|
344
|
+
if (prevConsumer !== undefined) {
|
|
345
|
+
prevConsumer.nextConsumer = nextConsumer;
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
producer.consumers = nextConsumer;
|
|
349
|
+
if (!consumerIsLive(producer)) {
|
|
350
|
+
let producerLink = producer.producers;
|
|
351
|
+
while (producerLink !== undefined) {
|
|
352
|
+
producerLink = producerRemoveLiveConsumerLink(producerLink);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return nextProducer;
|
|
357
|
+
}
|
|
358
|
+
function consumerIsLive(node) {
|
|
359
|
+
return node.consumerIsAlwaysLive || node.consumers !== undefined;
|
|
360
|
+
}
|
|
361
|
+
export function runPostProducerCreatedFn(node) {
|
|
362
|
+
postProducerCreatedFn?.(node);
|
|
363
|
+
}
|
|
364
|
+
export function setPostProducerCreatedFn(fn) {
|
|
365
|
+
const prev = postProducerCreatedFn;
|
|
366
|
+
postProducerCreatedFn = fn;
|
|
367
|
+
return prev;
|
|
368
|
+
}
|
|
369
|
+
// While a ReactiveNode is recomputing, it may not have destroyed previous links
|
|
370
|
+
// 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
|
|
371
|
+
function isValidLink(checkLink, consumer) {
|
|
372
|
+
const producersTail = consumer.producersTail;
|
|
373
|
+
if (producersTail !== undefined) {
|
|
374
|
+
let link = consumer.producers;
|
|
375
|
+
do {
|
|
376
|
+
if (link === checkLink) {
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
if (link === producersTail) {
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
link = link.nextProducer;
|
|
383
|
+
} while (link !== undefined);
|
|
384
|
+
}
|
|
385
|
+
return false;
|
|
386
|
+
}
|