Skip to content

Commit

Permalink
All contexts will be equal in 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed May 31, 2024
1 parent 459d398 commit 84e764b
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,9 @@ export interface StoryContextUpdate<TArgs = Args> {
}

export type ViewMode = 'story' | 'docs';
export interface StoryContextForLoaders<TRenderer extends Renderer = Renderer, TArgs = Args>
extends StoryContextForEnhancers<TRenderer, TArgs>,
Required<StoryContextUpdate<TArgs>> {
hooks: unknown;
viewMode: ViewMode;
originalStoryFn: StoryFn<TRenderer>;
}

export type LoaderFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (
context: StoryContextForLoaders<TRenderer, TArgs>
context: StoryContext<TRenderer, TArgs>
) => Promise<Record<string, any> | void> | Record<string, any> | void;

type Awaitable<T> = T | PromiseLike<T>;
Expand All @@ -267,29 +260,35 @@ export type BeforeEach<TRenderer extends Renderer = Renderer, TArgs = Args> = (
) => Awaitable<CleanupCallback | void>;

export interface StoryContext<TRenderer extends Renderer = Renderer, TArgs = Args>
extends StoryContextForLoaders<TRenderer, TArgs> {
extends StoryContextForEnhancers<TRenderer, TArgs>,
Required<StoryContextUpdate<TArgs>> {
hooks: unknown;
viewMode: ViewMode;
originalStoryFn: StoryFn<TRenderer>;
loaded: Record<string, any>;
abortSignal: AbortSignal;
canvasElement: TRenderer['canvasElement'];
step: StepFunction<TRenderer, TArgs>;
mount: () => Promise<void>;
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface StoryContextForLoaders<TRenderer extends Renderer = Renderer, TArgs = Args>
extends StoryContext<TRenderer, TArgs> {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface PlayFunctionContext<TRenderer extends Renderer = Renderer, TArgs = Args>
extends StoryContext<TRenderer, TArgs> {}

export type StepLabel = string;

export type StepFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (
label: StepLabel,
play: PlayFunction<TRenderer, TArgs>
) => Promise<void> | void;

export type PlayFunctionContext<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryContext<
TRenderer,
TArgs
> & {
step: StepFunction<TRenderer, TArgs>;
mount: () => Promise<void>;
};

export type PlayFunction<TRenderer extends Renderer = Renderer, TArgs = Args> = (
context: PlayFunctionContext<TRenderer, TArgs>
context: StoryContext<TRenderer, TArgs>
) => Promise<void> | void;

// This is the type of story function passed to a decorator -- does not rely on being passed any context
Expand Down Expand Up @@ -326,7 +325,7 @@ export type DecoratorApplicator<TRenderer extends Renderer = Renderer, TArgs = A
export type StepRunner<TRenderer extends Renderer = Renderer, TArgs = Args> = (
label: StepLabel,
play: PlayFunction<TRenderer, TArgs>,
context: PlayFunctionContext<TRenderer, TArgs>
context: StoryContext<TRenderer, TArgs>
) => Promise<void>;

export type BaseAnnotations<TRenderer extends Renderer = Renderer, TArgs = Args> = {
Expand Down

0 comments on commit 84e764b

Please sign in to comment.