Skip to content

Commit

Permalink
Clear resources on plan branch (#1530)
Browse files Browse the repository at this point in the history
allow `null` in subscribable store
  • Loading branch information
duranb authored Oct 30, 2024
1 parent cd7c918 commit 6a4afaa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
5 changes: 5 additions & 0 deletions src/components/timeline/Row.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@
}
});
}
} else if (simulationDataset === null) {
Object.entries(resourceRequestMap).forEach(([_key, value]) => {
value.controller?.abort();
});
resourceRequestMap = {};
}
$: onDragenter(dragenter);
Expand Down
8 changes: 2 additions & 6 deletions src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
$planEndTimeMs = getUnixEpochTime(data.initialPlan.end_time_doy);
$planStartTimeMs = getUnixEpochTime(data.initialPlan.start_time_doy);
$maxTimeRange = { end: $planEndTimeMs, start: $planStartTimeMs };
$simulationDatasetId = -1;
const querySimulationDatasetId = $page.url.searchParams.get(SearchParameters.SIMULATION_DATASET_ID);
if (querySimulationDatasetId) {
Expand Down Expand Up @@ -346,12 +347,7 @@
selectActivity(null, null);
}
$: if (
$initialPlan &&
$simulationDataset !== null &&
(getSimulationStatus($simulationDataset) === Status.Complete ||
getSimulationStatus($simulationDataset) === Status.Complete)
) {
$: if ($initialPlan && $simulationDataset !== null && getSimulationStatus($simulationDataset) === Status.Complete) {
const datasetId = $simulationDataset.dataset_id;
simulationDataAbortController?.abort();
simulationDataAbortController = new AbortController();
Expand Down
20 changes: 5 additions & 15 deletions src/stores/subscribable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ export function gqlSubscribable<T>(
await logout(EXPIRED_JWT);
} else {
subscribers.forEach(({ next }) => {
if (initialValue !== null) {
next(initialValue);
}
next(initialValue as T);
});
}
},
Expand All @@ -57,9 +55,7 @@ export function gqlSubscribable<T>(
if (!isEqual(value, newValue)) {
value = transformer(newValue);
subscribers.forEach(({ next }) => {
if (value !== null) {
next(value);
}
next(value as T);
});
}
}
Expand Down Expand Up @@ -182,9 +178,7 @@ export function gqlSubscribable<T>(
const unsubscribe = clientSubscribe();
const subscriber: Subscription<T> = { next, unsubscribe };
subscribers.add(subscriber);
if (value !== null) {
next(value);
}
next(value as T);

return () => {
subscriber.unsubscribe();
Expand All @@ -200,13 +194,9 @@ export function gqlSubscribable<T>(
}

function updateValue(fn: Updater<T>): void {
if (value !== null) {
value = fn(value);
}
value = fn(value as T);
subscribers.forEach(({ next }) => {
if (value !== null) {
next(value);
}
next(value as T);
});
}

Expand Down

0 comments on commit 6a4afaa

Please sign in to comment.