Skip to content

Commit

Permalink
(#1736) Add forceReRender support for Angular and Vue
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreenisrael committed Dec 27, 2017
1 parent ce935e6 commit 597387c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 2 additions & 0 deletions app/angular/src/client/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ const renderUI = () => {
};

reduxStore.subscribe(renderUI);

export const forceReRender = () => render(context, true);
8 changes: 4 additions & 4 deletions app/angular/src/client/preview/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function renderException(error) {
logger.error(error.stack);
}

export function renderMain(data, storyStore) {
export function renderMain(data, storyStore, forceRender) {
if (storyStore.size() === 0) return null;

const { selectedKind, selectedStory } = data;
Expand All @@ -39,7 +39,7 @@ export function renderMain(data, storyStore) {
// https://github.com/storybooks/react-storybook/issues/116

const reRender = selectedKind !== previousKind || previousStory !== selectedStory;
if (reRender) {
if (reRender || forceRender) {
// We need to unmount the existing set of components in the DOM node.
// Otherwise, React may not recrease instances for every story run.
// This could leads to issues like below:
Expand All @@ -54,14 +54,14 @@ export function renderMain(data, storyStore) {
return renderNgApp(story, context, reRender);
}

export default function renderPreview({ reduxStore, storyStore }) {
export default function renderPreview({ reduxStore, storyStore }, forceRender = false) {
const state = reduxStore.getState();
if (state.error) {
return renderException(state.error);
}

try {
return renderMain(state, storyStore);
return renderMain(state, storyStore, forceRender);
} catch (ex) {
return renderException(ex);
}
Expand Down
6 changes: 1 addition & 5 deletions app/react/src/client/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ const isBrowser =

const storyStore = new StoryStore();
/* eslint-disable no-underscore-dangle */
const reduxStore = createStore(
reducer,
window.__REDUX_DEVTOOLS_EXTENSION__ &&
window.__REDUX_DEVTOOLS_EXTENSION__({ name: 'Storybook Preview', instanceId: 'sbPreview' })
);
const reduxStore = createStore(reducer);
/* eslint-enable */
const context = { storyStore, reduxStore };

Expand Down
2 changes: 2 additions & 0 deletions app/vue/src/client/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ const renderUI = () => {
};

reduxStore.subscribe(renderUI);

export const forceReRender = () => render(context, true);
8 changes: 4 additions & 4 deletions app/vue/src/client/preview/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function renderRoot(options) {
app = new Vue(options);
}

export function renderMain(data, storyStore) {
export function renderMain(data, storyStore, forceRender) {
if (storyStore.size() === 0) return;

const { selectedKind, selectedStory } = data;
Expand All @@ -60,7 +60,7 @@ export function renderMain(data, storyStore) {
// renderMain() gets executed after each action. Actions will cause the whole
// story to re-render without this check.
// https://github.com/storybooks/react-storybook/issues/116
if (selectedKind !== previousKind || previousStory !== selectedStory) {
if (forceRender || selectedKind !== previousKind || previousStory !== selectedStory) {
// We need to unmount the existing set of components in the DOM node.
// Otherwise, React may not recrease instances for every story run.
// This could leads to issues like below:
Expand Down Expand Up @@ -97,14 +97,14 @@ export function renderMain(data, storyStore) {
});
}

export default function renderPreview({ reduxStore, storyStore }) {
export default function renderPreview({ reduxStore, storyStore }, forceRender = false) {
const state = reduxStore.getState();
if (state.error) {
return renderException(state.error);
}

try {
return renderMain(state, storyStore);
return renderMain(state, storyStore, forceRender);
} catch (ex) {
return renderException(ex);
}
Expand Down

0 comments on commit 597387c

Please sign in to comment.