Skip to content
Draft

wip #1881

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions packages/owl-core/src/computations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,35 @@ export function updateComputation(computation: ComputationAtom) {
return;
}
if (state === ComputationState.PENDING) {
for (const source of computation.sources) {
if (!("compute" in source)) {
continue;
if (computation.isDerived) {
for (const source of computation.sources) {
if (!("compute" in source)) {
continue;
}
updateComputation(source as ComputationAtom);
}
updateComputation(source as ComputationAtom);
}
// If the state is still not stale after processing the sources, it means
// none of the dependencies have changed.
// todo: test it
if (computation.state !== ComputationState.STALE) {
computation.state = ComputationState.EXECUTED;
return;
// If the state is still not stale after processing the sources, it means
// none of the dependencies have changed.
// todo: test it
if (computation.state !== ComputationState.STALE) {
computation.state = ComputationState.EXECUTED;
return;
}
} else {
computation.state = ComputationState.STALE;
}
}
// todo: test performance. We might want to avoid removing the atoms to
// directly re-add them at compute. Especially as we are making them stale.
removeSources(computation);
const previousComputation = currentComputation;
currentComputation = computation;
computation.value = computation.compute();
computation.state = ComputationState.EXECUTED;
currentComputation = previousComputation;
try {
computation.value = computation.compute();
computation.state = ComputationState.EXECUTED;
} finally {
currentComputation = previousComputation;
}
}

export function removeSources(computation: ComputationAtom) {
Expand Down Expand Up @@ -152,10 +159,11 @@ function markDownstream(computation: ComputationAtom) {
if (observer.state) {
continue;
}
observer.state = ComputationState.PENDING;
if (observer.isDerived) {
observer.state = ComputationState.PENDING;
stack.push(observer);
} else {
observer.state = ComputationState.STALE;
observers.push(observer);
}
}
Expand Down
Loading