easy-signal 3.2.0 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/reactiveSignal.d.ts
CHANGED
|
@@ -17,18 +17,19 @@ export declare const Timing: {
|
|
|
17
17
|
* the first argument is a function or `undefined` since the signal will assume any function is an updater function and
|
|
18
18
|
* any `undefined` value is a request to get the current value.
|
|
19
19
|
*/
|
|
20
|
-
export
|
|
21
|
-
(): T;
|
|
20
|
+
export interface ReactiveSignal<T> extends ComputedSignal<T> {
|
|
22
21
|
(value: T | ReactiveSignalUpdater<T>, set?: false): T;
|
|
23
22
|
(value: T, set: true): T;
|
|
24
|
-
|
|
25
|
-
};
|
|
23
|
+
}
|
|
26
24
|
/**
|
|
27
25
|
* A Computed Signal is a signal that is the result of a function that depends on other signals. The function is called
|
|
28
26
|
* whenever the computed signal is accessed if there are no subscribers, or whenever its dependent signals change if
|
|
29
27
|
* there are subscribers so that subscribers to the computed signal can be informed.
|
|
30
28
|
*/
|
|
31
|
-
export
|
|
29
|
+
export interface ComputedSignal<T> {
|
|
30
|
+
(): T;
|
|
31
|
+
subscribe: (subscriber: ReactiveSignalSubscriber<T>, timing?: Timing | null) => Unsubscribe;
|
|
32
|
+
}
|
|
32
33
|
/**
|
|
33
34
|
* A Signal Subscriber is a function that will be called whenever the signal's value changes. The subscriber will be
|
|
34
35
|
* called with the new value. The subscriber can be used to update the DOM or trigger other side effects.
|
package/dist/reactiveSignal.js
CHANGED
|
@@ -9,7 +9,6 @@ export const Timing = {
|
|
|
9
9
|
globalThis.requestAnimationFrame(fn);
|
|
10
10
|
},
|
|
11
11
|
};
|
|
12
|
-
// The context for the current run and its unsubscribes
|
|
13
12
|
let context = null;
|
|
14
13
|
// A map to keep track of listeners to subscription changes
|
|
15
14
|
const onSubscriptionChanges = new WeakMap();
|
|
@@ -100,13 +99,13 @@ export function subscribe(signal, subscriber, timing = Timing.Tick) {
|
|
|
100
99
|
};
|
|
101
100
|
}
|
|
102
101
|
// Set the current context so we can get the unsubscribe
|
|
103
|
-
context = { subscriber, unsubscribes: new Set() };
|
|
102
|
+
context = { prior: context, subscriber, unsubscribes: new Set() };
|
|
104
103
|
// Get the current value of the signal
|
|
105
104
|
const value = signal();
|
|
106
105
|
// Get the unsubscribe function for the subscriber
|
|
107
106
|
const unsubscribe = context.unsubscribes.values().next().value;
|
|
108
107
|
// Clear the current context
|
|
109
|
-
context =
|
|
108
|
+
context = context.prior;
|
|
110
109
|
// Call the subscriber with the current value
|
|
111
110
|
subscriber(value);
|
|
112
111
|
// Return the unsubscribe function
|
|
@@ -157,7 +156,7 @@ export function observe(fn, timing) {
|
|
|
157
156
|
return;
|
|
158
157
|
dirty = false;
|
|
159
158
|
// Set the context for the effect
|
|
160
|
-
context = { subscriber, unsubscribes: new Set() };
|
|
159
|
+
context = { prior: context, subscriber, unsubscribes: new Set() };
|
|
161
160
|
// Run the effect collecting all the unsubscribes from the signals that are called when it is run
|
|
162
161
|
fn();
|
|
163
162
|
// Filter out unchanged unsubscribes, leaving only those which no longer apply
|
|
@@ -167,7 +166,7 @@ export function observe(fn, timing) {
|
|
|
167
166
|
// Set the new unsubscribes
|
|
168
167
|
unsubscribes = context.unsubscribes;
|
|
169
168
|
// Clear the context
|
|
170
|
-
context =
|
|
169
|
+
context = context.prior;
|
|
171
170
|
};
|
|
172
171
|
// Call immediately (or on the next timing)
|
|
173
172
|
if (timing)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactiveSignal.js","sourceRoot":"","sources":["../src/reactiveSignal.ts"],"names":[],"mappings":"AASA,uEAAuE;AACvE,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,0DAA0D;IAC1D,IAAI,EAAE,CAAC,EAAc,EAAE,EAAE;QACvB,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IACD,mDAAmD;IACnD,cAAc,EAAE,CAAC,EAAc,EAA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
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
// The context for the current run and its unsubscribes
|
|
23
|
-
|
|
23
|
+
type Context = { prior: Context | null; subscriber: ReactiveSignalSubscriber<any>; unsubscribes: Set<Unsubscribe> };
|
|
24
|
+
let context: Context | null = null;
|
|
24
25
|
|
|
25
26
|
// A map to keep track of listeners to subscription changes
|
|
26
27
|
const onSubscriptionChanges = new WeakMap<ReactiveSignal<any>, Set<SubscriptionChange>>();
|
|
@@ -35,19 +36,20 @@ const onSubscriptionChanges = new WeakMap<ReactiveSignal<any>, Set<SubscriptionC
|
|
|
35
36
|
* the first argument is a function or `undefined` since the signal will assume any function is an updater function and
|
|
36
37
|
* any `undefined` value is a request to get the current value.
|
|
37
38
|
*/
|
|
38
|
-
export
|
|
39
|
-
(): T;
|
|
39
|
+
export interface ReactiveSignal<T> extends ComputedSignal<T> {
|
|
40
40
|
(value: T | ReactiveSignalUpdater<T>, set?: false): T;
|
|
41
41
|
(value: T, set: true): T;
|
|
42
|
-
|
|
43
|
-
};
|
|
42
|
+
}
|
|
44
43
|
|
|
45
44
|
/**
|
|
46
45
|
* A Computed Signal is a signal that is the result of a function that depends on other signals. The function is called
|
|
47
46
|
* whenever the computed signal is accessed if there are no subscribers, or whenever its dependent signals change if
|
|
48
47
|
* there are subscribers so that subscribers to the computed signal can be informed.
|
|
49
48
|
*/
|
|
50
|
-
export
|
|
49
|
+
export interface ComputedSignal<T> {
|
|
50
|
+
(): T;
|
|
51
|
+
subscribe: (subscriber: ReactiveSignalSubscriber<T>, timing?: Timing | null) => Unsubscribe;
|
|
52
|
+
}
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
55
|
* A Signal Subscriber is a function that will be called whenever the signal's value changes. The subscriber will be
|
|
@@ -185,7 +187,7 @@ export function subscribe<T>(
|
|
|
185
187
|
}
|
|
186
188
|
|
|
187
189
|
// Set the current context so we can get the unsubscribe
|
|
188
|
-
context = { subscriber, unsubscribes: new Set() };
|
|
190
|
+
context = { prior: context, subscriber, unsubscribes: new Set() };
|
|
189
191
|
|
|
190
192
|
// Get the current value of the signal
|
|
191
193
|
const value = signal();
|
|
@@ -194,7 +196,7 @@ export function subscribe<T>(
|
|
|
194
196
|
const unsubscribe = context.unsubscribes.values().next().value;
|
|
195
197
|
|
|
196
198
|
// Clear the current context
|
|
197
|
-
context =
|
|
199
|
+
context = context.prior;
|
|
198
200
|
|
|
199
201
|
// Call the subscriber with the current value
|
|
200
202
|
subscriber(value);
|
|
@@ -253,7 +255,7 @@ export function observe(fn: ReactiveSignalObserver, timing?: Timing): Unsubscrib
|
|
|
253
255
|
dirty = false;
|
|
254
256
|
|
|
255
257
|
// Set the context for the effect
|
|
256
|
-
context = { subscriber, unsubscribes: new Set() };
|
|
258
|
+
context = { prior: context, subscriber, unsubscribes: new Set() };
|
|
257
259
|
|
|
258
260
|
// Run the effect collecting all the unsubscribes from the signals that are called when it is run
|
|
259
261
|
fn();
|
|
@@ -268,7 +270,7 @@ export function observe(fn: ReactiveSignalObserver, timing?: Timing): Unsubscrib
|
|
|
268
270
|
unsubscribes = context.unsubscribes;
|
|
269
271
|
|
|
270
272
|
// Clear the context
|
|
271
|
-
context =
|
|
273
|
+
context = context.prior;
|
|
272
274
|
};
|
|
273
275
|
|
|
274
276
|
// Call immediately (or on the next timing)
|