@@ -30,7 +30,7 @@ export class Signal<T = any> {
30
30
/** @internal Marks the signal as requiring an update */
31
31
_requiresUpdate = false ;
32
32
/** @internal Determine if reads should eagerly activate value */
33
- _canActivate = false ;
33
+ _active = false ;
34
34
/** @internal Used to detect if there is a cycle in the graph */
35
35
_isComputing = false ;
36
36
@@ -43,16 +43,14 @@ export class Signal<T = any> {
43
43
}
44
44
45
45
peek ( ) {
46
- const shouldActivate = ! currentSignal || currentSignal . _canActivate ;
47
- if ( shouldActivate && this . _deps . size === 0 ) {
46
+ if ( ! this . _active ) {
48
47
activate ( this ) ;
49
48
}
50
49
return this . _value ;
51
50
}
52
51
53
52
get value ( ) {
54
- const shouldActivate = ! currentSignal || currentSignal . _canActivate ;
55
- if ( shouldActivate && this . _deps . size === 0 ) {
53
+ if ( ! this . _active ) {
56
54
activate ( this ) ;
57
55
}
58
56
@@ -69,15 +67,6 @@ export class Signal<T = any> {
69
67
currentSignal . _deps . add ( this ) ;
70
68
oldDeps . delete ( this ) ;
71
69
72
- // refresh stale value when this signal is read from withing
73
- // batching and when it has been marked already
74
- if (
75
- ( batchPending > 0 && this . _pending > 0 ) ||
76
- // Set up subscriptions during activation phase
77
- ( activating && this . _deps . size === 0 )
78
- ) {
79
- refreshStale ( this ) ;
80
- }
81
70
return this . _value ;
82
71
}
83
72
@@ -192,6 +181,7 @@ function sweep(subs: Set<Signal<any>>) {
192
181
}
193
182
194
183
function subscribe ( signal : Signal < any > , to : Signal < any > ) {
184
+ signal . _active = true ;
195
185
signal . _deps . add ( to ) ;
196
186
to . _subs . add ( signal ) ;
197
187
}
@@ -204,6 +194,7 @@ function unsubscribe(signal: Signal<any>, from: Signal<any>) {
204
194
// upwards and destroy all subscriptions until we encounter a writable
205
195
// signal or a signal that others listen to as well.
206
196
if ( from . _subs . size === 0 ) {
197
+ from . _active = false ;
207
198
from . _deps . forEach ( dep => unsubscribe ( from , dep ) ) ;
208
199
}
209
200
}
@@ -239,6 +230,7 @@ function refreshStale(signal: Signal) {
239
230
240
231
function activate ( signal : Signal ) {
241
232
activating = true ;
233
+ signal . _active = true ;
242
234
try {
243
235
refreshStale ( signal ) ;
244
236
} finally {
0 commit comments