Skip to content

Commit

Permalink
Make conservative run and conservative batchRun consistent with eacho…
Browse files Browse the repository at this point in the history
…ther
  • Loading branch information
pavish committed Oct 1, 2024
1 parent 7b0604e commit 4291b3b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
on:retry={init}
on:delete={cancel}
/>
{:else if !$previewRequest.hasInitialized}
{:else if !$previewRequest.hasSettled}
<div class="loading"><Spinner /></div>
{:else if $previewRequest.error}
<ErrorInfo
Expand Down
4 changes: 3 additions & 1 deletion mathesar_ui/src/stores/AsyncRpcApiStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ export default class AsyncRpcApiStore<Props, T, U = T> extends AsyncStore<
* that have already been initialized.
*/
static async runBatchConservatively(runners: BatchRunner[]) {
const toRun = runners.filter((runner) => !runner.getValue().hasInitialized);
const toRun = runners.filter(
(runner) => runner.getValue().isIdleAndUnsettled,
);
await AsyncRpcApiStore.runBatch(toRun);
}
}
18 changes: 8 additions & 10 deletions mathesar_ui/src/stores/AsyncStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ export class AsyncStoreValue<T, E> {
return !this.isLoading && this.settlement?.state === 'rejected';
}

get hasInitialized(): boolean {
get hasSettled(): boolean {
return this.settlement !== undefined;
}

get isIdleAndUnsettled(): boolean {
return !this.hasSettled && !this.isLoading;
}
}

export default class AsyncStore<Props = void, T = unknown>
Expand Down Expand Up @@ -152,18 +156,12 @@ export default class AsyncStore<Props = void, T = unknown>
}
}

/**
* Only runs if the current value is one of
* - not initialized
* - rejected
* - not loading
*/
async runConservatively(props: Props): Promise<AsyncStoreValue<T, string>> {
const value = get(this.value);
if (value.isLoading || value.isOk) {
return value;
if (value.isIdleAndUnsettled) {
return this.run(props);
}
return this.run(props);
return value;
}

/**
Expand Down

0 comments on commit 4291b3b

Please sign in to comment.