@tstdl/base 0.84.4 → 0.84.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/browser/document-controller.d.ts +1 -1
  2. package/browser/document-controller.js +1 -1
  3. package/browser/page-controller.d.ts +1 -1
  4. package/browser/page-controller.js +1 -1
  5. package/package.json +2 -1
  6. package/signals/api.d.ts +15 -0
  7. package/signals/api.js +40 -0
  8. package/signals/computed-with-dependencies.d.ts +2 -0
  9. package/signals/computed-with-dependencies.js +36 -0
  10. package/signals/implementation/api.d.ts +62 -0
  11. package/signals/implementation/api.js +43 -0
  12. package/signals/implementation/computed.d.ts +25 -0
  13. package/signals/implementation/computed.js +118 -0
  14. package/signals/implementation/configure.d.ts +1 -0
  15. package/signals/implementation/configure.js +38 -0
  16. package/signals/implementation/effect.d.ts +54 -0
  17. package/signals/implementation/effect.js +82 -0
  18. package/signals/implementation/errors.d.ts +9 -0
  19. package/signals/implementation/errors.js +41 -0
  20. package/signals/implementation/graph.d.ts +108 -0
  21. package/signals/implementation/graph.js +155 -0
  22. package/signals/implementation/index.d.ts +8 -0
  23. package/signals/implementation/index.js +25 -0
  24. package/signals/implementation/signal.d.ts +53 -0
  25. package/signals/implementation/signal.js +117 -0
  26. package/signals/implementation/untracked.d.ts +14 -0
  27. package/signals/implementation/untracked.js +39 -0
  28. package/signals/implementation/watch.d.ts +44 -0
  29. package/signals/implementation/watch.js +84 -0
  30. package/signals/index.d.ts +5 -0
  31. package/signals/index.js +22 -0
  32. package/signals/pipe.d.ts +7 -0
  33. package/signals/pipe.js +30 -0
  34. package/signals/to-observable.d.ts +16 -0
  35. package/signals/to-observable.js +38 -0
  36. package/signals/to-signal.d.ts +84 -0
  37. package/signals/to-signal.js +67 -0
@@ -0,0 +1,108 @@
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.io/license
7
+ */
8
+ export declare function setActiveConsumer(consumer: ReactiveNode | null): ReactiveNode | null;
9
+ /**
10
+ * A node in the reactive graph.
11
+ *
12
+ * Nodes can be producers of reactive values, consumers of other reactive values, or both.
13
+ *
14
+ * Producers are nodes that produce values, and can be depended upon by consumer nodes.
15
+ *
16
+ * Producers expose a monotonic `valueVersion` counter, and are responsible for incrementing this
17
+ * version when their value semantically changes. Some producers may produce their values lazily and
18
+ * thus at times need to be polled for potential updates to their value (and by extension their
19
+ * `valueVersion`). This is accomplished via the `onProducerUpdateValueVersion` method for
20
+ * implemented by producers, which should perform whatever calculations are necessary to ensure
21
+ * `valueVersion` is up to date.
22
+ *
23
+ * Consumers are nodes that depend on the values of producers and are notified when those values
24
+ * might have changed.
25
+ *
26
+ * Consumers do not wrap the reads they consume themselves, but rather can be set as the active
27
+ * reader via `setActiveConsumer`. Reads of producers that happen while a consumer is active will
28
+ * result in those producers being added as dependencies of that consumer node.
29
+ *
30
+ * The set of dependencies of a consumer is dynamic. Implementers expose a monotonically increasing
31
+ * `trackingVersion` counter, which increments whenever the consumer is about to re-run any reactive
32
+ * reads it needs and establish a new set of dependencies as a result.
33
+ *
34
+ * Producers store the last `trackingVersion` they've seen from `Consumer`s which have read them.
35
+ * This allows a producer to identify whether its record of the dependency is current or stale, by
36
+ * comparing the consumer's `trackingVersion` to the version at which the dependency was
37
+ * last observed.
38
+ */
39
+ export declare abstract class ReactiveNode {
40
+ private readonly id;
41
+ /**
42
+ * A cached weak reference to this node, which will be used in `ReactiveEdge`s.
43
+ */
44
+ private readonly ref;
45
+ /**
46
+ * Edges to producers on which this node depends (in its consumer capacity).
47
+ */
48
+ private readonly producers;
49
+ /**
50
+ * Edges to consumers on which this node depends (in its producer capacity).
51
+ */
52
+ private readonly consumers;
53
+ /**
54
+ * Monotonically increasing counter representing a version of this `Consumer`'s
55
+ * dependencies.
56
+ */
57
+ protected trackingVersion: number;
58
+ /**
59
+ * Monotonically increasing counter which increases when the value of this `Producer`
60
+ * semantically changes.
61
+ */
62
+ protected valueVersion: number;
63
+ /**
64
+ * Whether signal writes should be allowed while this `ReactiveNode` is the current consumer.
65
+ */
66
+ protected abstract readonly consumerAllowSignalWrites: boolean;
67
+ /**
68
+ * Called for consumers whenever one of their dependencies notifies that it might have a new
69
+ * value.
70
+ */
71
+ protected abstract onConsumerDependencyMayHaveChanged(): void;
72
+ /**
73
+ * Called for producers when a dependent consumer is checking if the producer's value has actually
74
+ * changed.
75
+ */
76
+ protected abstract onProducerUpdateValueVersion(): void;
77
+ /**
78
+ * Polls dependencies of a consumer to determine if they have actually changed.
79
+ *
80
+ * If this returns `false`, then even though the consumer may have previously been notified of a
81
+ * change, the values of its dependencies have not actually changed and the consumer should not
82
+ * rerun any reactions.
83
+ */
84
+ protected consumerPollProducersForChange(): boolean;
85
+ /**
86
+ * Notify all consumers of this producer that its value may have changed.
87
+ */
88
+ protected producerMayHaveChanged(): void;
89
+ /**
90
+ * Mark that this producer node has been accessed in the current reactive context.
91
+ */
92
+ protected producerAccessed(): void;
93
+ /**
94
+ * Whether this consumer currently has any producers registered.
95
+ */
96
+ protected get hasProducers(): boolean;
97
+ /**
98
+ * Whether this `ReactiveNode` in its producer capacity is currently allowed to initiate updates,
99
+ * based on the current consumer context.
100
+ */
101
+ protected get producerUpdatesAllowed(): boolean;
102
+ /**
103
+ * Checks if a `Producer` has a current value which is different than the value
104
+ * last seen at a specific version by a `Consumer` which recorded a dependency on
105
+ * this `Producer`.
106
+ */
107
+ private producerPollStatus;
108
+ }
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var graph_exports = {};
20
+ __export(graph_exports, {
21
+ ReactiveNode: () => ReactiveNode,
22
+ setActiveConsumer: () => setActiveConsumer
23
+ });
24
+ module.exports = __toCommonJS(graph_exports);
25
+ /**
26
+ * @license
27
+ * Copyright Google LLC All Rights Reserved.
28
+ *
29
+ * Use of this source code is governed by an MIT-style license that can be
30
+ * found in the LICENSE file at https://angular.io/license
31
+ */
32
+ let _nextReactiveId = 0;
33
+ let activeConsumer = null;
34
+ let inNotificationPhase = false;
35
+ function setActiveConsumer(consumer) {
36
+ const prev = activeConsumer;
37
+ activeConsumer = consumer;
38
+ return prev;
39
+ }
40
+ class ReactiveNode {
41
+ id = _nextReactiveId++;
42
+ /**
43
+ * A cached weak reference to this node, which will be used in `ReactiveEdge`s.
44
+ */
45
+ ref = new WeakRef(this);
46
+ /**
47
+ * Edges to producers on which this node depends (in its consumer capacity).
48
+ */
49
+ producers = /* @__PURE__ */ new Map();
50
+ /**
51
+ * Edges to consumers on which this node depends (in its producer capacity).
52
+ */
53
+ consumers = /* @__PURE__ */ new Map();
54
+ /**
55
+ * Monotonically increasing counter representing a version of this `Consumer`'s
56
+ * dependencies.
57
+ */
58
+ trackingVersion = 0;
59
+ /**
60
+ * Monotonically increasing counter which increases when the value of this `Producer`
61
+ * semantically changes.
62
+ */
63
+ valueVersion = 0;
64
+ /**
65
+ * Polls dependencies of a consumer to determine if they have actually changed.
66
+ *
67
+ * If this returns `false`, then even though the consumer may have previously been notified of a
68
+ * change, the values of its dependencies have not actually changed and the consumer should not
69
+ * rerun any reactions.
70
+ */
71
+ consumerPollProducersForChange() {
72
+ for (const [producerId, edge] of this.producers) {
73
+ const producer = edge.producerNode.deref();
74
+ if (producer === void 0 || edge.atTrackingVersion !== this.trackingVersion) {
75
+ this.producers.delete(producerId);
76
+ producer?.consumers.delete(this.id);
77
+ continue;
78
+ }
79
+ if (producer.producerPollStatus(edge.seenValueVersion)) {
80
+ return true;
81
+ }
82
+ }
83
+ return false;
84
+ }
85
+ /**
86
+ * Notify all consumers of this producer that its value may have changed.
87
+ */
88
+ producerMayHaveChanged() {
89
+ const prev = inNotificationPhase;
90
+ inNotificationPhase = true;
91
+ try {
92
+ for (const [consumerId, edge] of this.consumers) {
93
+ const consumer = edge.consumerNode.deref();
94
+ if (consumer === void 0 || consumer.trackingVersion !== edge.atTrackingVersion) {
95
+ this.consumers.delete(consumerId);
96
+ consumer?.producers.delete(this.id);
97
+ continue;
98
+ }
99
+ consumer.onConsumerDependencyMayHaveChanged();
100
+ }
101
+ } finally {
102
+ inNotificationPhase = prev;
103
+ }
104
+ }
105
+ /**
106
+ * Mark that this producer node has been accessed in the current reactive context.
107
+ */
108
+ producerAccessed() {
109
+ if (inNotificationPhase) {
110
+ throw new Error(`Assertion error: signal read during notification phase`);
111
+ }
112
+ if (activeConsumer === null) {
113
+ return;
114
+ }
115
+ let edge = activeConsumer.producers.get(this.id);
116
+ if (edge === void 0) {
117
+ edge = {
118
+ consumerNode: activeConsumer.ref,
119
+ producerNode: this.ref,
120
+ seenValueVersion: this.valueVersion,
121
+ atTrackingVersion: activeConsumer.trackingVersion
122
+ };
123
+ activeConsumer.producers.set(this.id, edge);
124
+ this.consumers.set(activeConsumer.id, edge);
125
+ } else {
126
+ edge.seenValueVersion = this.valueVersion;
127
+ edge.atTrackingVersion = activeConsumer.trackingVersion;
128
+ }
129
+ }
130
+ /**
131
+ * Whether this consumer currently has any producers registered.
132
+ */
133
+ get hasProducers() {
134
+ return this.producers.size > 0;
135
+ }
136
+ /**
137
+ * Whether this `ReactiveNode` in its producer capacity is currently allowed to initiate updates,
138
+ * based on the current consumer context.
139
+ */
140
+ get producerUpdatesAllowed() {
141
+ return activeConsumer?.consumerAllowSignalWrites !== false;
142
+ }
143
+ /**
144
+ * Checks if a `Producer` has a current value which is different than the value
145
+ * last seen at a specific version by a `Consumer` which recorded a dependency on
146
+ * this `Producer`.
147
+ */
148
+ producerPollStatus(lastSeenValueVersion) {
149
+ if (this.valueVersion !== lastSeenValueVersion) {
150
+ return true;
151
+ }
152
+ this.onProducerUpdateValueVersion();
153
+ return this.valueVersion !== lastSeenValueVersion;
154
+ }
155
+ }
@@ -0,0 +1,8 @@
1
+ export * from './api.js';
2
+ export * from './computed.js';
3
+ export * from './configure.js';
4
+ export * from './effect.js';
5
+ export * from './graph.js';
6
+ export * from './signal.js';
7
+ export * from './untracked.js';
8
+ export * from './watch.js';
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var implementation_exports = {};
17
+ module.exports = __toCommonJS(implementation_exports);
18
+ __reExport(implementation_exports, require("./api.js"), module.exports);
19
+ __reExport(implementation_exports, require("./computed.js"), module.exports);
20
+ __reExport(implementation_exports, require("./configure.js"), module.exports);
21
+ __reExport(implementation_exports, require("./effect.js"), module.exports);
22
+ __reExport(implementation_exports, require("./graph.js"), module.exports);
23
+ __reExport(implementation_exports, require("./signal.js"), module.exports);
24
+ __reExport(implementation_exports, require("./untracked.js"), module.exports);
25
+ __reExport(implementation_exports, require("./watch.js"), module.exports);
@@ -0,0 +1,53 @@
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.io/license
7
+ */
8
+ import type { Signal, ValueEqualityFn } from './api.js';
9
+ /**
10
+ * A `Signal` with a value that can be mutated via a setter interface.
11
+ *
12
+ * @developerPreview
13
+ */
14
+ export interface WritableSignal<T> extends Signal<T> {
15
+ /**
16
+ * Directly set the signal to a new value, and notify any dependents.
17
+ */
18
+ set(value: T): void;
19
+ /**
20
+ * Update the value of the signal based on its current value, and
21
+ * notify any dependents.
22
+ */
23
+ update(updateFn: (value: T) => T): void;
24
+ /**
25
+ * Update the current value by mutating it in-place, and
26
+ * notify any dependents.
27
+ */
28
+ mutate(mutatorFn: (value: T) => void): void;
29
+ /**
30
+ * Returns a readonly version of this signal. Readonly signals can be accessed to read their value
31
+ * but can't be changed using set, update or mutate methods. The readonly signals do _not_ have
32
+ * any built-in mechanism that would prevent deep-mutation of their value.
33
+ */
34
+ asReadonly(): Signal<T>;
35
+ }
36
+ /**
37
+ * Options passed to the `signal` creation function.
38
+ *
39
+ * @developerPreview
40
+ */
41
+ export interface CreateSignalOptions<T> {
42
+ /**
43
+ * A comparison function which defines equality for signal values.
44
+ */
45
+ equal?: ValueEqualityFn<T>;
46
+ }
47
+ /**
48
+ * Create a `Signal` that can be set or updated directly.
49
+ *
50
+ * @developerPreview
51
+ */
52
+ export declare function signal<T>(initialValue: T, options?: CreateSignalOptions<T>): WritableSignal<T>;
53
+ export declare function setPostSignalSetFn(fn: (() => void) | null): (() => void) | null;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var signal_exports = {};
20
+ __export(signal_exports, {
21
+ setPostSignalSetFn: () => setPostSignalSetFn,
22
+ signal: () => signal
23
+ });
24
+ module.exports = __toCommonJS(signal_exports);
25
+ var import_api = require("./api.js");
26
+ var import_errors = require("./errors.js");
27
+ var import_graph = require("./graph.js");
28
+ /**
29
+ * @license
30
+ * Copyright Google LLC All Rights Reserved.
31
+ *
32
+ * Use of this source code is governed by an MIT-style license that can be
33
+ * found in the LICENSE file at https://angular.io/license
34
+ */
35
+ let postSignalSetFn = null;
36
+ class WritableSignalImpl extends import_graph.ReactiveNode {
37
+ value;
38
+ equal;
39
+ readonlySignal;
40
+ consumerAllowSignalWrites = false;
41
+ constructor(value, equal) {
42
+ super();
43
+ this.value = value;
44
+ this.equal = equal;
45
+ }
46
+ onConsumerDependencyMayHaveChanged() {
47
+ }
48
+ onProducerUpdateValueVersion() {
49
+ }
50
+ /**
51
+ * Directly update the value of the signal to a new value, which may or may not be
52
+ * equal to the previous.
53
+ *
54
+ * In the event that `newValue` is semantically equal to the current value, `set` is
55
+ * a no-op.
56
+ */
57
+ set(newValue) {
58
+ if (!this.producerUpdatesAllowed) {
59
+ (0, import_errors.throwInvalidWriteToSignalError)();
60
+ }
61
+ if (!this.equal(this.value, newValue)) {
62
+ this.value = newValue;
63
+ this.valueVersion++;
64
+ this.producerMayHaveChanged();
65
+ postSignalSetFn?.();
66
+ }
67
+ }
68
+ /**
69
+ * Derive a new value for the signal from its current value using the `updater` function.
70
+ *
71
+ * This is equivalent to calling `set` on the result of running `updater` on the current
72
+ * value.
73
+ */
74
+ update(updater) {
75
+ if (!this.producerUpdatesAllowed) {
76
+ (0, import_errors.throwInvalidWriteToSignalError)();
77
+ }
78
+ this.set(updater(this.value));
79
+ }
80
+ /**
81
+ * Calls `mutator` on the current value and assumes that it has been mutated.
82
+ */
83
+ mutate(mutator) {
84
+ if (!this.producerUpdatesAllowed) {
85
+ (0, import_errors.throwInvalidWriteToSignalError)();
86
+ }
87
+ mutator(this.value);
88
+ this.valueVersion++;
89
+ this.producerMayHaveChanged();
90
+ postSignalSetFn?.();
91
+ }
92
+ asReadonly() {
93
+ if (this.readonlySignal === void 0) {
94
+ this.readonlySignal = (0, import_api.createSignalFromFunction)(this, () => this.signal());
95
+ }
96
+ return this.readonlySignal;
97
+ }
98
+ signal() {
99
+ this.producerAccessed();
100
+ return this.value;
101
+ }
102
+ }
103
+ function signal(initialValue, options) {
104
+ const signalNode = new WritableSignalImpl(initialValue, options?.equal ?? import_api.defaultEquals);
105
+ const signalFn = (0, import_api.createSignalFromFunction)(signalNode, signalNode.signal.bind(signalNode), {
106
+ set: signalNode.set.bind(signalNode),
107
+ update: signalNode.update.bind(signalNode),
108
+ mutate: signalNode.mutate.bind(signalNode),
109
+ asReadonly: signalNode.asReadonly.bind(signalNode)
110
+ });
111
+ return signalFn;
112
+ }
113
+ function setPostSignalSetFn(fn) {
114
+ const prev = postSignalSetFn;
115
+ postSignalSetFn = fn;
116
+ return prev;
117
+ }
@@ -0,0 +1,14 @@
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.io/license
7
+ */
8
+ /**
9
+ * Execute an arbitrary function in a non-reactive (non-tracking) context. The executed function
10
+ * can, optionally, return a value.
11
+ *
12
+ * @developerPreview
13
+ */
14
+ export declare function untracked<T>(nonReactiveReadsFn: () => T): T;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var untracked_exports = {};
20
+ __export(untracked_exports, {
21
+ untracked: () => untracked
22
+ });
23
+ module.exports = __toCommonJS(untracked_exports);
24
+ var import_graph = require("./graph.js");
25
+ /**
26
+ * @license
27
+ * Copyright Google LLC All Rights Reserved.
28
+ *
29
+ * Use of this source code is governed by an MIT-style license that can be
30
+ * found in the LICENSE file at https://angular.io/license
31
+ */
32
+ function untracked(nonReactiveReadsFn) {
33
+ const prevConsumer = (0, import_graph.setActiveConsumer)(null);
34
+ try {
35
+ return nonReactiveReadsFn();
36
+ } finally {
37
+ (0, import_graph.setActiveConsumer)(prevConsumer);
38
+ }
39
+ }
@@ -0,0 +1,44 @@
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.io/license
7
+ */
8
+ import { ReactiveNode } from './graph.js';
9
+ /**
10
+ * A cleanup function that can be optionally registered from the watch logic. If registered, the
11
+ * cleanup logic runs before the next watch execution.
12
+ */
13
+ export type WatchCleanupFn = () => void;
14
+ /**
15
+ * A callback passed to the watch function that makes it possible to register cleanup logic.
16
+ */
17
+ export type WatchCleanupRegisterFn = (cleanupFn: WatchCleanupFn) => void;
18
+ /**
19
+ * Watches a reactive expression and allows it to be scheduled to re-run
20
+ * when any dependencies notify of a change.
21
+ *
22
+ * `Watch` doesn't run reactive expressions itself, but relies on a consumer-
23
+ * provided scheduling operation to coordinate calling `Watch.run()`.
24
+ */
25
+ export declare class Watch extends ReactiveNode {
26
+ private watch;
27
+ private schedule;
28
+ protected readonly consumerAllowSignalWrites: boolean;
29
+ private dirty;
30
+ private cleanupFn;
31
+ private registerOnCleanup;
32
+ constructor(watch: (onCleanup: WatchCleanupRegisterFn) => void, schedule: (watch: Watch) => void, allowSignalWrites: boolean);
33
+ notify(): void;
34
+ protected onConsumerDependencyMayHaveChanged(): void;
35
+ protected onProducerUpdateValueVersion(): void;
36
+ /**
37
+ * Execute the reactive expression in the context of this `Watch` consumer.
38
+ *
39
+ * Should be called by the user scheduling algorithm when the provided
40
+ * `schedule` hook is called by `Watch`.
41
+ */
42
+ run(): void;
43
+ cleanup(): void;
44
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var watch_exports = {};
20
+ __export(watch_exports, {
21
+ Watch: () => Watch
22
+ });
23
+ module.exports = __toCommonJS(watch_exports);
24
+ var import_graph = require("./graph.js");
25
+ /**
26
+ * @license
27
+ * Copyright Google LLC All Rights Reserved.
28
+ *
29
+ * Use of this source code is governed by an MIT-style license that can be
30
+ * found in the LICENSE file at https://angular.io/license
31
+ */
32
+ const NOOP_CLEANUP_FN = () => {
33
+ };
34
+ class Watch extends import_graph.ReactiveNode {
35
+ watch;
36
+ schedule;
37
+ consumerAllowSignalWrites;
38
+ dirty = false;
39
+ cleanupFn = NOOP_CLEANUP_FN;
40
+ registerOnCleanup = (cleanupFn) => {
41
+ this.cleanupFn = cleanupFn;
42
+ };
43
+ constructor(watch, schedule, allowSignalWrites) {
44
+ super();
45
+ this.watch = watch;
46
+ this.schedule = schedule;
47
+ this.consumerAllowSignalWrites = allowSignalWrites;
48
+ }
49
+ notify() {
50
+ if (!this.dirty) {
51
+ this.schedule(this);
52
+ }
53
+ this.dirty = true;
54
+ }
55
+ onConsumerDependencyMayHaveChanged() {
56
+ this.notify();
57
+ }
58
+ onProducerUpdateValueVersion() {
59
+ }
60
+ /**
61
+ * Execute the reactive expression in the context of this `Watch` consumer.
62
+ *
63
+ * Should be called by the user scheduling algorithm when the provided
64
+ * `schedule` hook is called by `Watch`.
65
+ */
66
+ run() {
67
+ this.dirty = false;
68
+ if (this.trackingVersion !== 0 && !this.consumerPollProducersForChange()) {
69
+ return;
70
+ }
71
+ const prevConsumer = (0, import_graph.setActiveConsumer)(this);
72
+ this.trackingVersion++;
73
+ try {
74
+ this.cleanupFn();
75
+ this.cleanupFn = NOOP_CLEANUP_FN;
76
+ this.watch(this.registerOnCleanup);
77
+ } finally {
78
+ (0, import_graph.setActiveConsumer)(prevConsumer);
79
+ }
80
+ }
81
+ cleanup() {
82
+ this.cleanupFn();
83
+ }
84
+ }
@@ -0,0 +1,5 @@
1
+ export * from './api.js';
2
+ export * from './computed-with-dependencies.js';
3
+ export * from './pipe.js';
4
+ export * from './to-observable.js';
5
+ export * from './to-signal.js';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var signals_exports = {};
17
+ module.exports = __toCommonJS(signals_exports);
18
+ __reExport(signals_exports, require("./api.js"), module.exports);
19
+ __reExport(signals_exports, require("./computed-with-dependencies.js"), module.exports);
20
+ __reExport(signals_exports, require("./pipe.js"), module.exports);
21
+ __reExport(signals_exports, require("./to-observable.js"), module.exports);
22
+ __reExport(signals_exports, require("./to-signal.js"), module.exports);