@@ -12,14 +12,12 @@ const TRACKING = 1 << 5;
12
12
13
13
// Flags for Nodes.
14
14
const NODE_FREE = 1 << 0 ;
15
- const NODE_SUBSCRIBED = 1 << 1 ;
16
15
17
16
// A linked list node used to track dependencies (sources) and dependents (targets).
18
17
// Also used to remember the source's last version number that the target saw.
19
18
type Node = {
20
19
// A node may have the following flags:
21
20
// NODE_FREE when it's unclear whether the source is still a dependency of the target
22
- // NODE_SUBSCRIBED when the target has subscribed to listen change notifications from the source
23
21
_flags : number ;
24
22
25
23
// A source whose value the target depends on.
@@ -219,10 +217,8 @@ Signal.prototype._refresh = function () {
219
217
} ;
220
218
221
219
Signal . prototype . _subscribe = function ( node ) {
222
- if ( ! ( node . _flags & NODE_SUBSCRIBED ) ) {
223
- node . _flags |= NODE_SUBSCRIBED ;
220
+ if ( this . _targets !== node && node . _prevTarget === undefined ) {
224
221
node . _nextTarget = this . _targets ;
225
-
226
222
if ( this . _targets !== undefined ) {
227
223
this . _targets . _prevTarget = node ;
228
224
}
@@ -231,22 +227,18 @@ Signal.prototype._subscribe = function (node) {
231
227
} ;
232
228
233
229
Signal . prototype . _unsubscribe = function ( node ) {
234
- if ( node . _flags & NODE_SUBSCRIBED ) {
235
- node . _flags &= ~ NODE_SUBSCRIBED ;
236
-
237
- const prev = node . _prevTarget ;
238
- const next = node . _nextTarget ;
239
- if ( prev !== undefined ) {
240
- prev . _nextTarget = next ;
241
- node . _prevTarget = undefined ;
242
- }
243
- if ( next !== undefined ) {
244
- next . _prevTarget = prev ;
245
- node . _nextTarget = undefined ;
246
- }
247
- if ( node === this . _targets ) {
248
- this . _targets = next ;
249
- }
230
+ const prev = node . _prevTarget ;
231
+ const next = node . _nextTarget ;
232
+ if ( prev !== undefined ) {
233
+ prev . _nextTarget = next ;
234
+ node . _prevTarget = undefined ;
235
+ }
236
+ if ( next !== undefined ) {
237
+ next . _prevTarget = prev ;
238
+ node . _nextTarget = undefined ;
239
+ }
240
+ if ( node === this . _targets ) {
241
+ this . _targets = next ;
250
242
}
251
243
} ;
252
244
0 commit comments