Skip to content

Commit 8c3a94a

Browse files
committed
Refactor addDependency
1 parent 6e77711 commit 8c3a94a

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

packages/core/src/index.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,21 @@ function addDependency(signal: Signal): Node | undefined {
132132
}
133133
return node;
134134
} 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.
137136
node._version = 0;
138137

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;
151144
}
152145
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;
154150
evalContext._sources = node;
155151
}
156152

0 commit comments

Comments
 (0)