@@ -132,25 +132,21 @@ function addDependency(signal: Signal): Node | undefined {
132
132
}
133
133
return node ;
134
134
} else if ( node . _version === - 1 ) {
135
- // `signal` is an existing dependency from a previous evaluation. Reuse the dependency
136
- // node and move it to the front of the evaluation context's dependency list.
135
+ // `signal` is an existing dependency from a previous evaluation. Reuse it.
137
136
node . _version = 0 ;
138
137
139
- const head = evalContext . _sources ;
140
- if ( node !== head ) {
141
- const prev = node . _prevSource ;
142
- const next = node . _nextSource ;
143
- if ( prev !== undefined ) {
144
- prev . _nextSource = next ;
145
- }
146
- if ( next !== undefined ) {
147
- next . _prevSource = prev ;
148
- }
149
- if ( head !== undefined ) {
150
- head . _prevSource = node ;
138
+ // If `node` is not already the current head of the dependency list (i.e.
139
+ // there is a previous node in the list), then make `node` the new head.
140
+ if ( node . _prevSource !== undefined ) {
141
+ node . _prevSource . _nextSource = node . _nextSource ;
142
+ if ( node . _nextSource !== undefined ) {
143
+ node . _nextSource . _prevSource = node . _prevSource ;
151
144
}
152
145
node . _prevSource = undefined ;
153
- node . _nextSource = head ;
146
+ node . _nextSource = evalContext . _sources ;
147
+ // evalCotext._sources must be !== undefined (and !== node), because
148
+ // `node` was originally pointing to some previous node.
149
+ evalContext . _sources ! . _prevSource = node ;
154
150
evalContext . _sources = node ;
155
151
}
156
152
0 commit comments