Skip to content

Commit

Permalink
Change add() to accept a React component and props
Browse files Browse the repository at this point in the history
  • Loading branch information
jeef3 committed Apr 14, 2016
1 parent 9eef1fb commit 15dfcc6
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions dist/client/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ var ClientApi = function () {
});
}

var add = function add(storyName, fn) {
_this._storyStore.addStory(kind, storyName, fn);
var add = function add(storyName, fn, props) {
_this._storyStore.addStory(kind, storyName, fn, props);
return { add: add };
};

Expand Down
7 changes: 4 additions & 3 deletions dist/client/story_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var StoreStore = function () {

(0, _createClass3.default)(StoreStore, [{
key: "addStory",
value: function addStory(kind, name, fn) {
value: function addStory(kind, name, fn, props) {
if (!this._data[kind]) {
this._data[kind] = {
kind: kind,
Expand All @@ -41,7 +41,8 @@ var StoreStore = function () {
this._data[kind].stories[name] = {
name: name,
index: cnt++,
fn: fn
fn: fn,
props: props
};
}
}, {
Expand Down Expand Up @@ -87,7 +88,7 @@ var StoreStore = function () {
return null;
}

return storyInfo.fn;
return storyInfo;
}
}, {
key: "removeStoryKind",
Expand Down
2 changes: 1 addition & 1 deletion dist/client/ui/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function renderMain(data) {
// https://github.com/kadirahq/react-storybook/issues/81
_reactDom2.default.unmountComponentAtNode(rootEl);

return _reactDom2.default.render(story(), rootEl);
return _reactDom2.default.render(_react2.default.createElement(story.fn, story.props), rootEl);
}

function renderPreview(data) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default class ClientApi {
});
}

const add = (storyName, fn) => {
this._storyStore.addStory(kind, storyName, fn);
const add = (storyName, fn, props) => {
this._storyStore.addStory(kind, storyName, fn, props);
return { add };
};

Expand Down
5 changes: 3 additions & 2 deletions src/client/story_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class StoreStore {
this._data = {};
}

addStory(kind, name, fn) {
addStory(kind, name, fn, props) {
if (!this._data[kind]) {
this._data[kind] = {
kind,
Expand All @@ -18,6 +18,7 @@ export default class StoreStore {
name,
index: cnt++,
fn,
props
};
}

Expand Down Expand Up @@ -50,7 +51,7 @@ export default class StoreStore {
return null;
}

return storyInfo.fn;
return storyInfo;
}

removeStoryKind(kind) {
Expand Down
2 changes: 1 addition & 1 deletion src/client/ui/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function renderMain(data) {
// https://github.com/kadirahq/react-storybook/issues/81
ReactDOM.unmountComponentAtNode(rootEl);

return ReactDOM.render(story(), rootEl);
return ReactDOM.render(React.createElement(story.fn, story.props), rootEl);
}

export default function renderPreview(data) {
Expand Down

0 comments on commit 15dfcc6

Please sign in to comment.