aboutsummaryrefslogtreecommitdiffstats
path: root/uidev/src/stores/stories.ts
blob: 064bf275fba72522e0682b8aa9fe1629b3d13a70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { store } from './index';

export type StorySectionName = string;
export type StoryName = string;
export type StoryComponent = Function;

export interface IStories {
  name: string;
  component: StoryComponent;
}

export interface ISections {
  name: StorySectionName;
  stories: IStories[];
}

export interface IStoryStore {
  sections: ISections[];
}

export const storyStore: IStoryStore = {
  sections: [],
};

export const storiesOf = (name: StorySectionName) => {
  const length = storyStore.sections.push({
    name,
    stories: [],
  });

  const actions = {
    add: (name: StoryName, component: StoryComponent) => {
      storyStore.sections[length - 1].stories.push({
        name,
        component,
      });

      return actions;
    },
  };

  return actions;
};