1 | import "core-js/modules/es.array.reduce.js";
|
2 |
|
3 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
4 |
|
5 | const defaultContext = {
|
6 | id: 'unspecified',
|
7 | name: 'unspecified',
|
8 | kind: 'unspecified',
|
9 | parameters: {},
|
10 | args: {},
|
11 | argTypes: {},
|
12 | globals: {}
|
13 | };
|
14 | export const decorateStory = (storyFn, decorator, bindWithContext) => {
|
15 |
|
16 |
|
17 |
|
18 | const boundStoryFunction = bindWithContext(storyFn);
|
19 | return context => decorator(boundStoryFunction, context);
|
20 | };
|
21 | export const defaultDecorateStory = (storyFn, decorators) => {
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | const contextStore = {
|
29 | value: defaultContext
|
30 | };
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | const bindWithContext = decoratedStoryFn =>
|
43 | (_ref = {}) => {
|
44 | let contextUpdate = _objectWithoutPropertiesLoose(_ref, ["id", "name", "kind", "parameters"]);
|
45 |
|
46 | contextStore.value = Object.assign({}, contextStore.value, contextUpdate);
|
47 | return decoratedStoryFn(contextStore.value);
|
48 | };
|
49 |
|
50 | const decoratedWithContextStore = decorators.reduce((story, decorator) => decorateStory(story, decorator, bindWithContext), storyFn);
|
51 | return (context = defaultContext) => {
|
52 | contextStore.value = context;
|
53 | return decoratedWithContextStore(context);
|
54 | };
|
55 | }; |
\ | No newline at end of file |