-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] (#1736) ability to force re-render a story #2463
Changes from 4 commits
98fa5cd
6cb8d21
45f3a7f
50774cb
6d80f69
d4609e4
ce935e6
597387c
1fb6e3a
31a68d7
8e1caac
293bb7a
2be6ff2
a27b4bd
82699d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,13 @@ const isBrowser = | |
!(navigator.userAgent.indexOf('Node.js') > -1); | ||
|
||
const storyStore = new StoryStore(); | ||
const reduxStore = createStore(reducer); | ||
/* eslint-disable no-underscore-dangle */ | ||
const reduxStore = createStore( | ||
reducer, | ||
window.__REDUX_DEVTOOLS_EXTENSION__ && | ||
window.__REDUX_DEVTOOLS_EXTENSION__({ name: 'Storybook Preview', instanceId: 'sbPreview' }) | ||
); | ||
/* eslint-enable */ | ||
const context = { storyStore, reduxStore }; | ||
|
||
if (isBrowser) { | ||
|
@@ -53,3 +59,5 @@ const renderUI = () => { | |
}; | ||
|
||
reduxStore.subscribe(renderUI); | ||
|
||
export const forceReRender = () => renderUI(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the story didn't change, why would this work? Should return true, and the story won't be re-rendered? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind, I mis-interpreted the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just looking at that code, funnily enough and I think it's a bit broken, I was going to send a PR to fix it. The current (psuedo) logic is: render() {
// line linked above
if (storyDifferent) {
ReactDOM.unmountComponentAtNode(rootEl);
}
// later
ReactDOM.render(element, rootEl);
} So it always calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, if I was to fix the above (probably changing it to: We should consider if we want to support this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably the easiest way would be to add a "key" to the redux store that is changed when you call |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import { storiesOf, forceReRender } from '@storybook/react'; | ||
|
||
let count = 0; | ||
const increment = () => { | ||
count += 1; | ||
forceReRender(); | ||
}; | ||
|
||
storiesOf('Force ReRender', module).add('button', () => ( | ||
<button onClick={increment}> Click me to increment: {count} </button> | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's happening with this change? It seems unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, it is unrelated. It's enabling dev tools. Do you think it should be in a separate branch/pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think yeah, let's move to a separate PR