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

Commit

Permalink
Merge pull request #59 from kadirahq/fix-null-storyfn
Browse files Browse the repository at this point in the history
Validate storyFn property
  • Loading branch information
Muhammed Thanish authored Aug 26, 2016
2 parents 235ea90 + a9bab1b commit 30c69e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions dist/preview/components/StoryView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ var StoryView = function (_Component) {

var _this = (0, _possibleConstructorReturn3.default)(this, (_ref = StoryView.__proto__ || (0, _getPrototypeOf2.default)(StoryView)).call.apply(_ref, [this, props].concat(args)));

_this.state = { storyFn: function storyFn() {
return null;
} };
_this.state = { storyFn: null };
_this.props.events.on('story', function (storyFn) {
return _this.setState({ storyFn: storyFn });
});
Expand All @@ -56,6 +54,9 @@ var StoryView = function (_Component) {
(0, _createClass3.default)(StoryView, [{
key: 'render',
value: function render() {
if (!this.state.storyFn) {
return null;
}
return this.state.storyFn();
}
}]);
Expand Down
5 changes: 4 additions & 1 deletion src/preview/components/StoryView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import React, { Component } from 'react';
export default class StoryView extends Component {
constructor(props, ...args) {
super(props, ...args);
this.state = {storyFn: () => null};
this.state = {storyFn: null};
this.props.events.on('story', storyFn => this.setState({storyFn}));
}

render() {
if (!this.state.storyFn) {
return null;
}
return this.state.storyFn();
}
}

0 comments on commit 30c69e4

Please sign in to comment.