Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Make render function of WrapStory pure #61

Merged
merged 1 commit into from
Oct 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/KnobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ export default class KnobManager {
if (!knobStore) {
knobStore = this.knobStoreMap[key] = new KnobStore();
}
this.knobStore = knobStore;

const props = { context, storyFn, channel, knobStore };
this.knobStore = knobStore;
knobStore.markAllUnused();
const initialContent = storyFn(context);
const props = { context, storyFn, channel, knobStore, initialContent };
return (<WrapStory {...props} />);
}

Expand Down
16 changes: 8 additions & 8 deletions src/components/WrapStory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class WrapStory extends React.Component {
this.resetKnobs = this.resetKnobs.bind(this);
this.setPaneKnobs = this.setPaneKnobs.bind(this);
this._knobsAreReset = false;
this.state = {};
this.state = { storyContent: this.props.initialContent };
}

componentDidMount() {
Expand Down Expand Up @@ -35,24 +35,23 @@ export default class WrapStory extends React.Component {

knobChanged(change) {
const { name, value } = change;
const { knobStore } = this.props;
const { knobStore, storyFn, context } = this.props;
// Update the related knob and it's value.
const knobOptions = knobStore.get(name);
knobOptions.value = value;
this.forceUpdate();
knobStore.markAllUnused();
this.setState({ storyContent: storyFn(context) });
}

resetKnobs() {
const { knobStore } = this.props;
const { knobStore, storyFn, context } = this.props;
knobStore.reset();
this.forceUpdate();
this.setState({ storyContent: storyFn(context) });
this.setPaneKnobs();
}

render() {
const { storyFn, context, knobStore } = this.props;
knobStore.markAllUnused();
return storyFn(context);
return this.state.storyContent;
}
}

Expand All @@ -61,4 +60,5 @@ WrapStory.propTypes = {
storyFn: React.PropTypes.func,
channel: React.PropTypes.object,
knobStore: React.PropTypes.object,
initialContent: React.PropTypes.object,
};