Skip to content

Commit

Permalink
La til storybook asyncAction.
Browse files Browse the repository at this point in the history
Kan brukast istadenfor vanleg action funksjon i stories der ein skal erstatte ein async funksjon. Unngår med det typescript feil på disse.
  • Loading branch information
josstn committed Oct 31, 2024
1 parent 4031e2c commit 1910e65
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/v2/gui/src/storybook/asyncAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { action, type ActionOptions, type HandlerFunction } from '@storybook/addon-actions';

export type AsyncHandlerFunction = (...args: Parameters<HandlerFunction>) => Promise<ReturnType<HandlerFunction>>;

/**
* Kan brukast i storybook istadenfor standard action, når funksjonen ein skal erstatte er async.
* Unngår med dette typescript klaging.
*/
export const asyncAction = (name: string, options: ActionOptions = {}): AsyncHandlerFunction => {
const handler = action(name, options);
return async (...args: Parameters<typeof handler>) => handler(...args);
};

0 comments on commit 1910e65

Please sign in to comment.