diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-09-27 16:12:58 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-09-27 16:12:58 +0200 |
commit | 748c46172bb9f5cd33e0ced3869930626c38105d (patch) | |
tree | be0d5d19745edd78930cdd319911813c956a684b | |
parent | 51f4cd6dae0511d77bea71c6abf94c86aacdf67f (diff) | |
download | gitbook-748c46172bb9f5cd33e0ced3869930626c38105d.zip gitbook-748c46172bb9f5cd33e0ced3869930626c38105d.tar.gz gitbook-748c46172bb9f5cd33e0ced3869930626c38105d.tar.bz2 |
Fix reducers mutating the state instead of creating a new one
-rw-r--r-- | packages/gitbook-core/src/components/HTMLContent.js | 10 | ||||
-rw-r--r-- | packages/gitbook-core/src/createReducer.js | 14 | ||||
-rw-r--r-- | packages/gitbook-plugin-theme-default/src/index.js | 1 |
3 files changed, 20 insertions, 5 deletions
diff --git a/packages/gitbook-core/src/components/HTMLContent.js b/packages/gitbook-core/src/components/HTMLContent.js index 979fe0c..4ce41f6 100644 --- a/packages/gitbook-core/src/components/HTMLContent.js +++ b/packages/gitbook-core/src/components/HTMLContent.js @@ -12,9 +12,15 @@ const { InjectedComponent } = require('./InjectedComponent'); function inject(injectedProps, Component) { return (props) => { + const cleanProps = { + ...props, + className: props.className + }; + delete cleanProps['class']; + return ( - <InjectedComponent {...injectedProps(props)}> - <Component {...props} /> + <InjectedComponent {...injectedProps(cleanProps)}> + <Component {...cleanProps} /> </InjectedComponent> ); }; diff --git a/packages/gitbook-core/src/createReducer.js b/packages/gitbook-core/src/createReducer.js index 6860277..2ebecfb 100644 --- a/packages/gitbook-core/src/createReducer.js +++ b/packages/gitbook-core/src/createReducer.js @@ -9,8 +9,18 @@ function createReducer(name, reduce) { return (state, action) => { const value = state[name]; - state[name] = reduce(value, action); - return state; + const newValue = reduce(value, action); + + if (newValue === value) { + return state; + } + + const newState = { + ...state, + [name]: newValue + }; + + return newState; }; } diff --git a/packages/gitbook-plugin-theme-default/src/index.js b/packages/gitbook-plugin-theme-default/src/index.js index 64d4433..2ef5c63 100644 --- a/packages/gitbook-plugin-theme-default/src/index.js +++ b/packages/gitbook-plugin-theme-default/src/index.js @@ -45,7 +45,6 @@ let ThemeBody = React.createClass({ }); ThemeBody = GitBook.connect(ThemeBody, ({page, summary, sidebar}) => { - console.log('connect!'); return { page, summary, sidebar }; }); |