From 6a4afaa0ad6021f230a7563a49ff118a39bc6ac2 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 30 Oct 2024 11:06:02 -0700 Subject: [PATCH] Clear resources on plan branch (#1530) allow `null` in subscribable store --- src/components/timeline/Row.svelte | 5 +++++ src/routes/plans/[id]/+page.svelte | 8 ++------ src/stores/subscribable.ts | 20 +++++--------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/components/timeline/Row.svelte b/src/components/timeline/Row.svelte index 5f803dd4c5..8e07830199 100644 --- a/src/components/timeline/Row.svelte +++ b/src/components/timeline/Row.svelte @@ -314,6 +314,11 @@ } }); } + } else if (simulationDataset === null) { + Object.entries(resourceRequestMap).forEach(([_key, value]) => { + value.controller?.abort(); + }); + resourceRequestMap = {}; } $: onDragenter(dragenter); diff --git a/src/routes/plans/[id]/+page.svelte b/src/routes/plans/[id]/+page.svelte index a37b4b015e..869aa0d4e9 100644 --- a/src/routes/plans/[id]/+page.svelte +++ b/src/routes/plans/[id]/+page.svelte @@ -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) { @@ -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(); diff --git a/src/stores/subscribable.ts b/src/stores/subscribable.ts index 0bd4b68040..8445086d1e 100644 --- a/src/stores/subscribable.ts +++ b/src/stores/subscribable.ts @@ -44,9 +44,7 @@ export function gqlSubscribable( await logout(EXPIRED_JWT); } else { subscribers.forEach(({ next }) => { - if (initialValue !== null) { - next(initialValue); - } + next(initialValue as T); }); } }, @@ -57,9 +55,7 @@ export function gqlSubscribable( if (!isEqual(value, newValue)) { value = transformer(newValue); subscribers.forEach(({ next }) => { - if (value !== null) { - next(value); - } + next(value as T); }); } } @@ -182,9 +178,7 @@ export function gqlSubscribable( const unsubscribe = clientSubscribe(); const subscriber: Subscription = { next, unsubscribe }; subscribers.add(subscriber); - if (value !== null) { - next(value); - } + next(value as T); return () => { subscriber.unsubscribe(); @@ -200,13 +194,9 @@ export function gqlSubscribable( } function updateValue(fn: Updater): void { - if (value !== null) { - value = fn(value); - } + value = fn(value as T); subscribers.forEach(({ next }) => { - if (value !== null) { - next(value); - } + next(value as T); }); }