Make the wrapStory decorator simple to use.

This commit is contained in:
Arunoda Susiripala 2016-09-09 09:12:40 +05:30
parent dc1d9df0fe
commit cf38bf7d43
3 changed files with 12 additions and 14 deletions

View File

@ -12,7 +12,7 @@ import {
import Button from './Button'; import Button from './Button';
storiesOf('Button', module) storiesOf('Button', module)
.addDecorator((story, context) => (withKnobs(story)(context))) .addDecorator(withKnobs)
.add('default view', () => ( .add('default view', () => (
<Button <Button
onClick={ action('button clicked') } onClick={ action('button clicked') }

View File

@ -30,8 +30,7 @@ export default class KnobManager {
return knobStore.get(name).value; return knobStore.get(name).value;
} }
wrapStory(storyFn, channel) { wrapStory(channel, storyFn, context) {
return context => {
const key = `${context.kind}:::${context.story}`; const key = `${context.kind}:::${context.story}`;
let knobStore = this.knobStoreMap[key]; let knobStore = this.knobStoreMap[key];
@ -42,6 +41,5 @@ export default class KnobManager {
const props = { context, storyFn, channel, knobStore }; const props = { context, storyFn, channel, knobStore };
return (<WrapStory {...props} />); return (<WrapStory {...props} />);
};
} }
} }

View File

@ -23,7 +23,7 @@ export function object(name, value) {
return manager.knob(name, { type: 'object', value }); return manager.knob(name, { type: 'object', value });
} }
export function withKnobs(storyFn) { export function withKnobs(storyFn, context) {
const channel = addons.getChannel(); const channel = addons.getChannel();
return manager.wrapStory(storyFn, channel); return manager.wrapStory(channel, storyFn, context);
} }