Skip to content

Commit

Permalink
Drop second parameter, and read root element type off framework
Browse files Browse the repository at this point in the history
tmeasday committed Nov 2, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent a7f29b7 commit 95da68c
Showing 13 changed files with 89 additions and 117 deletions.
10 changes: 5 additions & 5 deletions code/lib/client-api/src/ClientApi.ts
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ import { StoryStoreFacade } from './StoryStoreFacade';

// ClientApi (and StoreStore) are really singletons. However they are not created until the
// relevant framework instanciates them via `start.js`. The good news is this happens right away.
let singleton: ClientApi<Framework, any>;
let singleton: ClientApi<Framework>;

const warningAlternatives = {
addDecorator: `Instead, use \`export const decorators = [];\` in your \`preview.js\`.`,
@@ -111,10 +111,10 @@ export const setGlobalRender = (render: StoryFn<Framework>) => {
};

const invalidStoryTypes = new Set(['string', 'number', 'boolean', 'symbol']);
export class ClientApi<TFramework extends Framework, TStorybookRoot = HTMLElement> {
facade: StoryStoreFacade<TFramework, TStorybookRoot>;
export class ClientApi<TFramework extends Framework> {
facade: StoryStoreFacade<TFramework>;

storyStore?: StoryStore<TFramework, TStorybookRoot>;
storyStore?: StoryStore<TFramework>;

private addons: Addon_ClientApiAddons<TFramework['storyResult']>;

@@ -124,7 +124,7 @@ export class ClientApi<TFramework extends Framework, TStorybookRoot = HTMLElemen
// just use numeric indexes
private lastFileName = 0;

constructor({ storyStore }: { storyStore?: StoryStore<TFramework, TStorybookRoot> } = {}) {
constructor({ storyStore }: { storyStore?: StoryStore<TFramework> } = {}) {
this.facade = new StoryStoreFacade();

this.addons = {};
6 changes: 3 additions & 3 deletions code/lib/client-api/src/StoryStoreFacade.ts
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@ import type { StoryStore } from '@storybook/store';
import { userOrAutoTitle, sortStoriesV6 } from '@storybook/store';
import { logger } from '@storybook/client-logger';

export class StoryStoreFacade<TFramework extends Framework, TStorybookRoot = HTMLElement> {
projectAnnotations: Store_NormalizedProjectAnnotations<TFramework, TStorybookRoot>;
export class StoryStoreFacade<TFramework extends Framework> {
projectAnnotations: Store_NormalizedProjectAnnotations<TFramework>;

entries: Record<StoryId, Addon_IndexEntry & { componentId?: ComponentId }>;

@@ -54,7 +54,7 @@ export class StoryStoreFacade<TFramework extends Framework, TStorybookRoot = HTM
});
}

getStoryIndex(store: StoryStore<TFramework, TStorybookRoot>) {
getStoryIndex(store: StoryStore<TFramework>) {
const fileNameOrder = Object.keys(this.csfExports);
const storySortParameter = this.projectAnnotations.parameters?.options?.storySort;

30 changes: 14 additions & 16 deletions code/lib/preview-web/src/Preview.tsx
Original file line number Diff line number Diff line change
@@ -44,18 +44,18 @@ export type MaybePromise<T> = Promise<T> | T;
const renderToDOMDeprecated = deprecate(() => {},
`\`renderToDOM\` is deprecated, please rename to \`renderToRoot\``);

export class Preview<TFramework extends Framework, TStorybookRoot = HTMLElement> {
export class Preview<TFramework extends Framework> {
serverChannel?: Channel;

storyStore: StoryStore<TFramework, TStorybookRoot>;
storyStore: StoryStore<TFramework>;

getStoryIndex?: () => Store_StoryIndex;

importFn?: Store_ModuleImportFn;

renderToRoot?: RenderToRoot<TFramework, TStorybookRoot>;
renderToRoot?: RenderToRoot<TFramework>;

storyRenders: StoryRender<TFramework, TStorybookRoot>[] = [];
storyRenders: StoryRender<TFramework>[] = [];

previewEntryError?: Error;

@@ -83,7 +83,7 @@ export class Preview<TFramework extends Framework, TStorybookRoot = HTMLElement>
// getProjectAnnotations has been run, thus this slightly awkward approach
getStoryIndex?: () => Store_StoryIndex;
importFn: Store_ModuleImportFn;
getProjectAnnotations: () => MaybePromise<ProjectAnnotations<TFramework, TStorybookRoot>>;
getProjectAnnotations: () => MaybePromise<ProjectAnnotations<TFramework>>;
}) {
// We save these two on initialization in case `getProjectAnnotations` errors,
// in which case we may need them later when we recover.
@@ -108,8 +108,8 @@ export class Preview<TFramework extends Framework, TStorybookRoot = HTMLElement>
}

getProjectAnnotationsOrRenderError(
getProjectAnnotations: () => MaybePromise<ProjectAnnotations<TFramework, TStorybookRoot>>
): Store_PromiseLike<ProjectAnnotations<TFramework, TStorybookRoot>> {
getProjectAnnotations: () => MaybePromise<ProjectAnnotations<TFramework>>
): Store_PromiseLike<ProjectAnnotations<TFramework>> {
return SynchronousPromise.resolve()
.then(getProjectAnnotations)
.then((projectAnnotations) => {
@@ -136,9 +136,7 @@ export class Preview<TFramework extends Framework, TStorybookRoot = HTMLElement>
}

// If initialization gets as far as project annotations, this function runs.
initializeWithProjectAnnotations(
projectAnnotations: ProjectAnnotations<TFramework, TStorybookRoot>
) {
initializeWithProjectAnnotations(projectAnnotations: ProjectAnnotations<TFramework>) {
this.storyStore.setProjectAnnotations(projectAnnotations);

this.setInitialGlobals();
@@ -199,7 +197,7 @@ export class Preview<TFramework extends Framework, TStorybookRoot = HTMLElement>
async onGetProjectAnnotationsChanged({
getProjectAnnotations,
}: {
getProjectAnnotations: () => MaybePromise<ProjectAnnotations<TFramework, TStorybookRoot>>;
getProjectAnnotations: () => MaybePromise<ProjectAnnotations<TFramework>>;
}) {
delete this.previewEntryError;

@@ -311,11 +309,11 @@ export class Preview<TFramework extends Framework, TStorybookRoot = HTMLElement>
// main to be consistent with the previous behaviour. In the future,
// we will change it to go ahead and load the story, which will end up being
// "instant", although async.
renderStoryToElement(story: Store_Story<TFramework>, element: TStorybookRoot) {
renderStoryToElement(story: Store_Story<TFramework>, element: TFramework['rootElement']) {
if (!this.renderToRoot)
throw new Error(`Cannot call renderStoryToElement before initialization`);

const render = new StoryRender<TFramework, TStorybookRoot>(
const render = new StoryRender<TFramework>(
this.channel,
this.storyStore,
this.renderToRoot,
@@ -335,9 +333,9 @@ export class Preview<TFramework extends Framework, TStorybookRoot = HTMLElement>

async teardownRender(
render:
| StoryRender<TFramework, TStorybookRoot>
| TemplateDocsRender<TFramework, TStorybookRoot>
| StandaloneDocsRender<TFramework, TStorybookRoot>,
| StoryRender<TFramework>
| TemplateDocsRender<TFramework>
| StandaloneDocsRender<TFramework>,
{ viewModeChanged }: { viewModeChanged?: boolean } = {}
) {
this.storyRenders = this.storyRenders.filter((r) => r !== render);
55 changes: 21 additions & 34 deletions code/lib/preview-web/src/PreviewWeb.tsx
Original file line number Diff line number Diff line change
@@ -50,28 +50,25 @@ function focusInInput(event: Event) {
return /input|textarea/i.test(target.tagName) || target.getAttribute('contenteditable') !== null;
}

type PossibleRender<TFramework extends Framework, TStorybookRoot = HTMLElement> =
| StoryRender<TFramework, TStorybookRoot>
| TemplateDocsRender<TFramework, TStorybookRoot>
| StandaloneDocsRender<TFramework, TStorybookRoot>;

function isStoryRender<TFramework extends Framework, TStorybookRoot>(
r: PossibleRender<TFramework, TStorybookRoot>
): r is StoryRender<TFramework, TStorybookRoot> {
type PossibleRender<TFramework extends Framework> =
| StoryRender<TFramework>
| TemplateDocsRender<TFramework>
| StandaloneDocsRender<TFramework>;

function isStoryRender<TFramework extends Framework>(
r: PossibleRender<TFramework>
): r is StoryRender<TFramework> {
return r.type === 'story';
}

export class PreviewWeb<TFramework extends Framework, TStorybookRoot = HTMLElement> extends Preview<
TFramework,
TStorybookRoot
> {
export class PreviewWeb<TFramework extends Framework> extends Preview<TFramework> {
selectionStore: SelectionStore;

view: View<TStorybookRoot>;
view: View<TFramework['rootElement']>;

currentSelection?: Store_Selection;

currentRender?: PossibleRender<TFramework, TStorybookRoot>;
currentRender?: PossibleRender<TFramework>;

constructor({
// I'm not quite sure how to express this -- if you don't pass a view, you need to ensure
@@ -80,7 +77,7 @@ export class PreviewWeb<TFramework extends Framework, TStorybookRoot = HTMLEleme
view = new WebView() as any,
selectionStore = new UrlStore(),
}: {
view?: View<TStorybookRoot>;
view?: View<TFramework['rootElement']>;
selectionStore?: SelectionStore;
} = {}) {
super();
@@ -99,9 +96,7 @@ export class PreviewWeb<TFramework extends Framework, TStorybookRoot = HTMLEleme
this.channel.on(PRELOAD_ENTRIES, this.onPreloadStories.bind(this));
}

initializeWithProjectAnnotations(
projectAnnotations: ProjectAnnotations<TFramework, TStorybookRoot>
) {
initializeWithProjectAnnotations(projectAnnotations: ProjectAnnotations<TFramework>) {
return super
.initializeWithProjectAnnotations(projectAnnotations)
.then(() => this.setInitialGlobals());
@@ -182,7 +177,7 @@ export class PreviewWeb<TFramework extends Framework, TStorybookRoot = HTMLEleme
async onGetProjectAnnotationsChanged({
getProjectAnnotations,
}: {
getProjectAnnotations: () => MaybePromise<ProjectAnnotations<TFramework, TStorybookRoot>>;
getProjectAnnotations: () => MaybePromise<ProjectAnnotations<TFramework>>;
}) {
await super.onGetProjectAnnotationsChanged({ getProjectAnnotations });

@@ -302,9 +297,9 @@ export class PreviewWeb<TFramework extends Framework, TStorybookRoot = HTMLEleme
await this.teardownRender(this.currentRender);
}

let render: PossibleRender<TFramework, TStorybookRoot>;
let render: PossibleRender<TFramework>;
if (entry.type === 'story') {
render = new StoryRender<TFramework, TStorybookRoot>(
render = new StoryRender<TFramework>(
this.channel,
this.storyStore,
(...args: Parameters<typeof renderToRoot>) => {
@@ -317,17 +312,9 @@ export class PreviewWeb<TFramework extends Framework, TStorybookRoot = HTMLEleme
'story'
);
} else if (entry.standalone) {
render = new StandaloneDocsRender<TFramework, TStorybookRoot>(
this.channel,
this.storyStore,
entry
);
render = new StandaloneDocsRender<TFramework>(this.channel, this.storyStore, entry);
} else {
render = new TemplateDocsRender<TFramework, TStorybookRoot>(
this.channel,
this.storyStore,
entry
);
render = new TemplateDocsRender<TFramework>(this.channel, this.storyStore, entry);
}

// We need to store this right away, so if the story changes during
@@ -406,8 +393,8 @@ export class PreviewWeb<TFramework extends Framework, TStorybookRoot = HTMLEleme

if (isStoryRender(render)) {
if (!render.story) throw new Error('Render has not been prepared!');
this.storyRenders.push(render as StoryRender<TFramework, TStorybookRoot>);
(this.currentRender as StoryRender<TFramework, TStorybookRoot>).renderToElement(
this.storyRenders.push(render as StoryRender<TFramework>);
(this.currentRender as StoryRender<TFramework>).renderToElement(
this.view.prepareForStory(render.story)
);
} else {
@@ -420,7 +407,7 @@ export class PreviewWeb<TFramework extends Framework, TStorybookRoot = HTMLEleme
}

async teardownRender(
render: PossibleRender<TFramework, TStorybookRoot>,
render: PossibleRender<TFramework>,
{ viewModeChanged = false }: { viewModeChanged?: boolean } = {}
) {
this.storyRenders = this.storyRenders.filter((r) => r !== render);
6 changes: 2 additions & 4 deletions code/lib/preview-web/src/docs-context/DocsContext.ts
Original file line number Diff line number Diff line change
@@ -13,9 +13,7 @@ import type { Channel } from '@storybook/channels';

import type { DocsContextProps } from './DocsContextProps';

export class DocsContext<TFramework extends Framework, TStorybookRoot = HTMLElement>
implements DocsContextProps<TFramework>
{
export class DocsContext<TFramework extends Framework> implements DocsContextProps<TFramework> {
private componentStoriesValue: Store_Story<TFramework>[];

private storyIdToCSFFile: Map<StoryId, Store_CSFFile<TFramework>>;
@@ -28,7 +26,7 @@ export class DocsContext<TFramework extends Framework, TStorybookRoot = HTMLElem

constructor(
public channel: Channel,
protected store: StoryStore<TFramework, TStorybookRoot>,
protected store: StoryStore<TFramework>,
public renderStoryToElement: DocsContextProps['renderStoryToElement'],
/** The CSF files known (via the index) to be refererenced by this docs file */
csfFiles: Store_CSFFile<TFramework>[],
9 changes: 6 additions & 3 deletions code/lib/preview-web/src/render/Render.ts
Original file line number Diff line number Diff line change
@@ -9,15 +9,18 @@ export type RenderType = 'story' | 'docs';
* - Tracking the state of the rendering as it moves between preparing, rendering and tearing down.
* - Tracking what is rendered to know if a change requires re-rendering or teardown + recreation.
*/
export interface Render<TFramework extends Framework, TStorybookRoot = HTMLElement> {
export interface Render<TFramework extends Framework> {
type: RenderType;
id: StoryId;
isPreparing: () => boolean;
isEqual: (other: Render<TFramework, TStorybookRoot>) => boolean;
isEqual: (other: Render<TFramework>) => boolean;
disableKeyListeners: boolean;
teardown?: (options: { viewModeChanged: boolean }) => Promise<void>;
torndown: boolean;
renderToElement: (canvasElement: TStorybookRoot, renderStoryToElement?: any) => Promise<void>;
renderToElement: (
canvasElement: TFramework['rootElement'],
renderStoryToElement?: any
) => Promise<void>;
}

export const PREPARE_ABORTED = new Error('prepareAborted');
14 changes: 6 additions & 8 deletions code/lib/preview-web/src/render/StandaloneDocsRender.ts
Original file line number Diff line number Diff line change
@@ -24,9 +24,7 @@ import { DocsContext } from '../docs-context/DocsContext';
* - *.mdx file that may or may not reference a specific CSF file with `<Meta of={} />`
*/

export class StandaloneDocsRender<TFramework extends Framework, TStorybookRoot = HTMLElement>
implements Render<TFramework, TStorybookRoot>
{
export class StandaloneDocsRender<TFramework extends Framework> implements Render<TFramework> {
public readonly type: RenderType = 'docs';

public readonly id: StoryId;
@@ -47,7 +45,7 @@ export class StandaloneDocsRender<TFramework extends Framework, TStorybookRoot =

constructor(
protected channel: Channel,
protected store: StoryStore<TFramework, TStorybookRoot>,
protected store: StoryStore<TFramework>,
public entry: Addon_IndexEntry
) {
this.id = entry.id;
@@ -68,22 +66,22 @@ export class StandaloneDocsRender<TFramework extends Framework, TStorybookRoot =
this.preparing = false;
}

isEqual(other: Render<TFramework, TStorybookRoot>): boolean {
isEqual(other: Render<TFramework>): boolean {
return !!(
this.id === other.id &&
this.exports &&
this.exports === (other as StandaloneDocsRender<TFramework, TStorybookRoot>).exports
this.exports === (other as StandaloneDocsRender<TFramework>).exports
);
}

async renderToElement(
canvasElement: TStorybookRoot,
canvasElement: TFramework['rootElement'],
renderStoryToElement: DocsContextProps['renderStoryToElement']
) {
if (!this.exports || !this.csfFiles || !this.store.projectAnnotations)
throw new Error('Cannot render docs before preparing');

const docsContext = new DocsContext<TFramework, TStorybookRoot>(
const docsContext = new DocsContext<TFramework>(
this.channel,
this.store,
renderStoryToElement,
18 changes: 8 additions & 10 deletions code/lib/preview-web/src/render/StoryRender.ts
Original file line number Diff line number Diff line change
@@ -47,9 +47,7 @@ export type RenderContextCallbacks<TFramework extends Framework> = Pick<
'showMain' | 'showError' | 'showException'
>;

export class StoryRender<TFramework extends Framework, TStorybookRoot = HTMLElement>
implements Render<TFramework, TStorybookRoot>
{
export class StoryRender<TFramework extends Framework> implements Render<TFramework> {
public type: RenderType = 'story';

public story?: Store_Story<TFramework>;
@@ -58,7 +56,7 @@ export class StoryRender<TFramework extends Framework, TStorybookRoot = HTMLElem

private abortController?: AbortController;

private canvasElement?: TStorybookRoot;
private canvasElement?: TFramework['rootElement'];

private notYetRendered = true;

@@ -70,8 +68,8 @@ export class StoryRender<TFramework extends Framework, TStorybookRoot = HTMLElem

constructor(
public channel: Channel,
public store: StoryStore<TFramework, TStorybookRoot>,
private renderToScreen: RenderToRoot<TFramework, TStorybookRoot>,
public store: StoryStore<TFramework>,
private renderToScreen: RenderToRoot<TFramework>,
private callbacks: RenderContextCallbacks<TFramework>,
public id: StoryId,
public viewMode: ViewMode,
@@ -112,11 +110,11 @@ export class StoryRender<TFramework extends Framework, TStorybookRoot = HTMLElem
}

// The two story "renders" are equal and have both loaded the same story
isEqual(other: Render<TFramework, TStorybookRoot>): boolean {
isEqual(other: Render<TFramework>): boolean {
return !!(
this.id === other.id &&
this.story &&
this.story === (other as StoryRender<TFramework, TStorybookRoot>).story
this.story === (other as StoryRender<TFramework>).story
);
}

@@ -128,7 +126,7 @@ export class StoryRender<TFramework extends Framework, TStorybookRoot = HTMLElem
return ['rendering', 'playing'].includes(this.phase as RenderPhase);
}

async renderToElement(canvasElement: TStorybookRoot) {
async renderToElement(canvasElement: TFramework['rootElement']) {
this.canvasElement = canvasElement;

// FIXME: this comment
@@ -188,7 +186,7 @@ export class StoryRender<TFramework extends Framework, TStorybookRoot = HTMLElem
// and we need to ensure we render it with the new values
...this.storyContext(),
abortSignal,
// We should consider parameterizing the story types with TStorybookRoot in the future
// We should consider parameterizing the story types with TFramework['rootElement'] in the future
canvasElement: canvasElement as any,
};
const renderContext: Store_RenderContext<TFramework> = {
14 changes: 6 additions & 8 deletions code/lib/preview-web/src/render/TemplateDocsRender.ts
Original file line number Diff line number Diff line change
@@ -27,9 +27,7 @@ import { DocsContext } from '../docs-context/DocsContext';
* - *.stories.mdx files, where the MDX compiler produces a CSF file with a `.parameter.docs.page`
* parameter containing the compiled content of the MDX file.
*/
export class TemplateDocsRender<TFramework extends Framework, TStorybookRoot = HTMLElement>
implements Render<TFramework, TStorybookRoot>
{
export class TemplateDocsRender<TFramework extends Framework> implements Render<TFramework> {
public readonly type: RenderType = 'docs';

public readonly id: StoryId;
@@ -50,7 +48,7 @@ export class TemplateDocsRender<TFramework extends Framework, TStorybookRoot = H

constructor(
protected channel: Channel,
protected store: StoryStore<TFramework, TStorybookRoot>,
protected store: StoryStore<TFramework>,
public entry: Addon_IndexEntry
) {
this.id = entry.id;
@@ -85,21 +83,21 @@ export class TemplateDocsRender<TFramework extends Framework, TStorybookRoot = H
this.preparing = false;
}

isEqual(other: Render<TFramework, TStorybookRoot>): boolean {
isEqual(other: Render<TFramework>): boolean {
return !!(
this.id === other.id &&
this.story &&
this.story === (other as TemplateDocsRender<TFramework, TStorybookRoot>).story
this.story === (other as TemplateDocsRender<TFramework>).story
);
}

async renderToElement(
canvasElement: TStorybookRoot,
canvasElement: TFramework['rootElement'],
renderStoryToElement: DocsContextProps['renderStoryToElement']
) {
if (!this.story || !this.csfFiles) throw new Error('Cannot render docs before preparing');

const docsContext = new DocsContext<TFramework, TStorybookRoot>(
const docsContext = new DocsContext<TFramework>(
this.channel,
this.store,
renderStoryToElement,
8 changes: 4 additions & 4 deletions code/lib/store/src/StoryStore.ts
Original file line number Diff line number Diff line change
@@ -37,12 +37,12 @@ import { processCSFFile, prepareStory, normalizeProjectAnnotations } from './csf
const CSF_CACHE_SIZE = 1000;
const STORY_CACHE_SIZE = 10000;

export class StoryStore<TFramework extends Framework, TStorybookRoot = HTMLElement> {
export class StoryStore<TFramework extends Framework> {
storyIndex?: StoryIndexStore;

importFn?: Store_ModuleImportFn;

projectAnnotations?: Store_NormalizedProjectAnnotations<TFramework, TStorybookRoot>;
projectAnnotations?: Store_NormalizedProjectAnnotations<TFramework>;

globals?: GlobalsStore;

@@ -77,7 +77,7 @@ export class StoryStore<TFramework extends Framework, TStorybookRoot = HTMLEleme
});
}

setProjectAnnotations(projectAnnotations: ProjectAnnotations<TFramework, TStorybookRoot>) {
setProjectAnnotations(projectAnnotations: ProjectAnnotations<TFramework>) {
// By changing `this.projectAnnotations, we implicitly invalidate the `prepareStoryWithCache`
this.projectAnnotations = normalizeProjectAnnotations(projectAnnotations);
const { globals, globalTypes } = projectAnnotations;
@@ -145,7 +145,7 @@ export class StoryStore<TFramework extends Framework, TStorybookRoot = HTMLEleme
);
}

loadAllCSFFiles(): Store_PromiseLike<StoryStore<TFramework, TStorybookRoot>['cachedCSFFiles']> {
loadAllCSFFiles(): Store_PromiseLike<StoryStore<TFramework>['cachedCSFFiles']> {
if (!this.storyIndex) throw new Error(`loadAllCSFFiles called before initialization`);

const importPaths: Record<Path, StoryId> = {};
7 changes: 2 additions & 5 deletions code/lib/store/src/csf/normalizeProjectAnnotations.ts
Original file line number Diff line number Diff line change
@@ -9,15 +9,12 @@ import { inferArgTypes } from '../inferArgTypes';
import { inferControls } from '../inferControls';
import { normalizeInputTypes } from './normalizeInputTypes';

export function normalizeProjectAnnotations<TFramework extends Framework, TStorybookRoot>({
export function normalizeProjectAnnotations<TFramework extends Framework>({
argTypes,
globalTypes,
argTypesEnhancers,
...annotations
}: ProjectAnnotations<TFramework, TStorybookRoot>): Store_NormalizedProjectAnnotations<
TFramework,
TStorybookRoot
> {
}: ProjectAnnotations<TFramework>): Store_NormalizedProjectAnnotations<TFramework> {
return {
...(argTypes && { argTypes: normalizeInputTypes(argTypes as ArgTypes) }),
...(globalTypes && { globalTypes: normalizeInputTypes(globalTypes) }),
4 changes: 2 additions & 2 deletions code/lib/store/src/csf/prepareStory.ts
Original file line number Diff line number Diff line change
@@ -41,10 +41,10 @@ const argTypeDefaultValueWarning = deprecate(
//
// Note that this story function is *stateless* in the sense that it does not track args or globals
// Instead, it is expected these are tracked separately (if necessary) and are passed into each invocation.
export function prepareStory<TFramework extends Framework, TStorybookRoot = HTMLElement>(
export function prepareStory<TFramework extends Framework>(
storyAnnotations: Store_NormalizedStoryAnnotations<TFramework>,
componentAnnotations: Store_NormalizedComponentAnnotations<TFramework>,
projectAnnotations: Store_NormalizedProjectAnnotations<TFramework, TStorybookRoot>
projectAnnotations: Store_NormalizedProjectAnnotations<TFramework>
): Store_Story<TFramework> {
// NOTE: in the current implementation we are doing everything once, up front, rather than doing
// anything at render time. The assumption is that as we don't load all the stories at once, this
25 changes: 10 additions & 15 deletions code/lib/types/src/modules/store.ts
Original file line number Diff line number Diff line change
@@ -43,28 +43,23 @@ export type Store_ModuleImportFn = (path: Path) => Store_PromiseLike<Store_Modul
type Store_MaybePromise<T> = Promise<T> | T;

export type TeardownRenderToRoot = () => Store_MaybePromise<void>;
export type RenderToRoot<TFramework extends Framework, TStorybookRoot = HTMLElement> = (
export type RenderToRoot<TFramework extends Framework> = (
context: Store_RenderContext<TFramework>,
element: TStorybookRoot
element: TFramework['rootElement']
) => Store_MaybePromise<void | TeardownRenderToRoot>;

export type ProjectAnnotations<
TFramework extends Framework,
TStorybookRoot = HTMLElement
> = CsfProjectAnnotations<TFramework> & {
renderToRoot?: RenderToRoot<TFramework, TStorybookRoot>;
export type ProjectAnnotations<TFramework extends Framework> = CsfProjectAnnotations<TFramework> & {
renderToRoot?: RenderToRoot<TFramework>;

/* @deprecated use renderToRoot */
renderToDOM?: RenderToRoot<TFramework, TStorybookRoot>;
renderToDOM?: RenderToRoot<TFramework>;
};

export type Store_NormalizedProjectAnnotations<
TFramework extends Framework = Framework,
TStorybookRoot = HTMLElement
> = ProjectAnnotations<TFramework, TStorybookRoot> & {
argTypes?: StrictArgTypes;
globalTypes?: StrictGlobalTypes;
};
export type Store_NormalizedProjectAnnotations<TFramework extends Framework = Framework> =
ProjectAnnotations<TFramework> & {
argTypes?: StrictArgTypes;
globalTypes?: StrictGlobalTypes;
};

export type Store_NormalizedComponentAnnotations<TFramework extends Framework = Framework> =
ComponentAnnotations<TFramework> & {

0 comments on commit 95da68c

Please sign in to comment.