Skip to content

Commit

Permalink
Merge pull request #1009 from centerofci/export_const_not_let
Browse files Browse the repository at this point in the history
Use more strict export for `proceed` function within `CancelOrProceedButtonPair` component
  • Loading branch information
pavish committed Jan 28, 2022
2 parents f62f516 + 644b4a3 commit 3b7c26b
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@
export let canProceed = true;
export let canCancel = true;
export let isProcessing = false;
/**
* Bind to this function if you want to be able to programmatically call the
* proceed function from within the parent component and show the loading
* spinner while the promise is resolving.
*/
export let proceed: () => Promise<void> = async () => {};
let spinnerButtonProceed: () => Promise<void> = async () => {};
export function proceed(): Promise<void> {
// Why do we have `spinnerButtonProceed` and `proceed` separately?
//
// Because we want to export a const (`proceed` here) to make it clear to
// consuming components that they can't supply their own function. AND we
// need for _this_ component to be able to change the function in the
// process of binding to the value from lower down in the component tree.
return spinnerButtonProceed();
}
$: fullCancelButton = { ...cancelButtonDefaults, ...cancelButton };
$: fullProceedButton = { ...proceedButtonDefaults, ...proceedButton };
Expand All @@ -56,7 +62,7 @@
</Button>
<SpinnerButton
bind:isProcessing
bind:proceed
bind:proceed={spinnerButtonProceed}
onClick={onProceed}
icon={fullProceedButton.icon}
label={fullProceedButton.label}
Expand Down

0 comments on commit 3b7c26b

Please sign in to comment.