@tstdl/base 0.84.3 → 0.84.5
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/.eslintrc.json +0 -4
- package/browser/document-controller.d.ts +26 -0
- package/browser/document-controller.js +88 -0
- package/browser/element-controller.d.ts +2 -8
- package/browser/element-controller.js +1 -17
- package/browser/frame-controller.d.ts +23 -0
- package/browser/frame-controller.js +52 -0
- package/browser/index.d.ts +3 -0
- package/browser/index.js +3 -0
- package/browser/locator-controller.d.ts +16 -0
- package/browser/locator-controller.js +60 -0
- package/browser/page-controller.d.ts +13 -23
- package/browser/page-controller.js +11 -62
- package/package.json +2 -1
- package/signals/api.d.ts +14 -0
- package/signals/api.js +57 -0
- package/signals/implementation/api.d.ts +62 -0
- package/signals/implementation/api.js +43 -0
- package/signals/implementation/computed.d.ts +26 -0
- package/signals/implementation/computed.js +125 -0
- package/signals/implementation/effect.d.ts +54 -0
- package/signals/implementation/effect.js +82 -0
- package/signals/implementation/errors.d.ts +9 -0
- package/signals/implementation/errors.js +41 -0
- package/signals/implementation/graph.d.ts +108 -0
- package/signals/implementation/graph.js +155 -0
- package/signals/implementation/index.d.ts +7 -0
- package/signals/implementation/index.js +24 -0
- package/signals/implementation/signal.d.ts +53 -0
- package/signals/implementation/signal.js +117 -0
- package/signals/implementation/untracked.d.ts +14 -0
- package/signals/implementation/untracked.js +39 -0
- package/signals/implementation/watch.d.ts +44 -0
- package/signals/implementation/watch.js +84 -0
- package/signals/index.d.ts +4 -0
- package/signals/index.js +21 -0
- package/signals/pipe.d.ts +7 -0
- package/signals/pipe.js +30 -0
- package/signals/to-observable.d.ts +16 -0
- package/signals/to-observable.js +38 -0
- package/signals/to-signal.d.ts +84 -0
- package/signals/to-signal.js +67 -0
|
@@ -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,24 @@
|
|
|
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("./effect.js"), module.exports);
|
|
21
|
+
__reExport(implementation_exports, require("./graph.js"), module.exports);
|
|
22
|
+
__reExport(implementation_exports, require("./signal.js"), module.exports);
|
|
23
|
+
__reExport(implementation_exports, require("./untracked.js"), module.exports);
|
|
24
|
+
__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
|
+
}
|
package/signals/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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("./pipe.js"), module.exports);
|
|
20
|
+
__reExport(signals_exports, require("./to-observable.js"), module.exports);
|
|
21
|
+
__reExport(signals_exports, require("./to-signal.js"), module.exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OperatorFunction } from 'rxjs';
|
|
2
|
+
import type { Signal } from './api.js';
|
|
3
|
+
export declare function pipe<I, A>(signal: Signal<I>, op1: OperatorFunction<I, A>): Signal<A>;
|
|
4
|
+
export declare function pipe<I, A, B>(signal: Signal<I>, op1: OperatorFunction<I, A>, op2: OperatorFunction<A, B>): Signal<B>;
|
|
5
|
+
export declare function pipe<I, A, B, C>(signal: Signal<I>, op1: OperatorFunction<I, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>): Signal<C>;
|
|
6
|
+
export declare function pipe<I, A, B, C, D>(signal: Signal<I>, op1: OperatorFunction<I, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>): Signal<D>;
|
|
7
|
+
export declare function pipe<I, A, B, C, D, E>(signal: Signal<I>, op1: OperatorFunction<I, A>, op2: OperatorFunction<A, B>, op3: OperatorFunction<B, C>, op4: OperatorFunction<C, D>, op5: OperatorFunction<D, E>): Signal<E>;
|
package/signals/pipe.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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 pipe_exports = {};
|
|
20
|
+
__export(pipe_exports, {
|
|
21
|
+
pipe: () => pipe
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(pipe_exports);
|
|
24
|
+
var import_to_observable = require("./to-observable.js");
|
|
25
|
+
var import_to_signal = require("./to-signal.js");
|
|
26
|
+
function pipe(signal, ...operators) {
|
|
27
|
+
const observable = (0, import_to_observable.toObservable)(signal, { emitImmediately: true });
|
|
28
|
+
const piped = observable.pipe(...operators);
|
|
29
|
+
return (0, import_to_signal.toSignal)(piped, { requireSync: true });
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import type { Signal } from './api.js';
|
|
3
|
+
export type ToObservableOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Immediately run inner effect after creation without scheduling - for advanced use cases.
|
|
6
|
+
*/
|
|
7
|
+
emitImmediately: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Exposes the value of an Angular `Signal` as an RxJS `Observable`.
|
|
11
|
+
*
|
|
12
|
+
* The signal's value will be propagated into the `Observable`'s subscribers using an `effect`.
|
|
13
|
+
*
|
|
14
|
+
* `toObservable` must be called in an injection context.
|
|
15
|
+
*/
|
|
16
|
+
export declare function toObservable<T>(source: Signal<T>, options?: ToObservableOptions): Observable<T>;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 to_observable_exports = {};
|
|
20
|
+
__export(to_observable_exports, {
|
|
21
|
+
toObservable: () => toObservable
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(to_observable_exports);
|
|
24
|
+
var import_rxjs = require("rxjs");
|
|
25
|
+
var import_api = require("./api.js");
|
|
26
|
+
function toObservable(source, options) {
|
|
27
|
+
return new import_rxjs.Observable((subscriber) => {
|
|
28
|
+
const effectRef = (0, import_api.effect)(() => {
|
|
29
|
+
try {
|
|
30
|
+
const value = source();
|
|
31
|
+
(0, import_api.untracked)(() => subscriber.next(value));
|
|
32
|
+
} catch (error) {
|
|
33
|
+
(0, import_api.untracked)(() => subscriber.error(error));
|
|
34
|
+
}
|
|
35
|
+
}, { allowSignalWrites: true, runImmediately: options?.emitImmediately });
|
|
36
|
+
return () => effectRef.destroy();
|
|
37
|
+
});
|
|
38
|
+
}
|