Skip to content

Commit

Permalink
WIP -- consume new stories format
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Apr 21, 2020
1 parent 603dfc5 commit a415dc3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 10 additions & 0 deletions lib/api/src/lib/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ export interface StoriesRaw {
[id: string]: StoryInput;
}

type Parameters = { [key: string]: any };
type StoryKind = string;
export interface StoryStoreData {
globalParameters: Parameters;
kindParameters: {
[kind: StoryKind]: Parameters
};
stories:
}

const warnUsingHierarchySeparatorsAndShowRoots = deprecate(
() => {},
dedent`
Expand Down
13 changes: 6 additions & 7 deletions lib/api/src/modules/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
StoriesHash,
Story,
Group,
StoriesRaw,
StoryStoreData,
StoryId,
isStory,
Root,
isRoot,
StoriesRaw,
} from '../lib/stories';

import { Args, ModuleFn } from '../index';
Expand Down Expand Up @@ -299,7 +300,7 @@ export const init: ModuleFn = ({
}
});

fullAPI.on(SET_STORIES, function handleSetStories(data: { stories: StoriesRaw }) {
fullAPI.on(SET_STORIES, function handleSetStories(data: StoryStoreData | StoriesRaw) {
// the event originates from an iframe, event.source is the iframe's location origin + pathname
const { storyId } = store.getState();
const { source }: { source: string } = this;
Expand All @@ -308,11 +309,9 @@ export const init: ModuleFn = ({
switch (sourceType) {
// if it's a local source, we do nothing special
case 'local': {
fullAPI.setStories(data.stories);
const options = storyId
? fullAPI.getParameters(storyId, 'options')
: fullAPI.getParameters(Object.keys(data.stories)[0], 'options');
fullAPI.setOptions(options);
fullAPI.setStoryStoreData(data);

fullAPI.setOptions((data as StoryStoreData).globalParameters.options);
break;
}

Expand Down

0 comments on commit a415dc3

Please sign in to comment.