summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-09-27 16:12:58 +0200
committerSamy Pesse <samypesse@gmail.com>2016-09-27 16:12:58 +0200
commit748c46172bb9f5cd33e0ced3869930626c38105d (patch)
treebe0d5d19745edd78930cdd319911813c956a684b /packages/gitbook-core/src
parent51f4cd6dae0511d77bea71c6abf94c86aacdf67f (diff)
downloadgitbook-748c46172bb9f5cd33e0ced3869930626c38105d.zip
gitbook-748c46172bb9f5cd33e0ced3869930626c38105d.tar.gz
gitbook-748c46172bb9f5cd33e0ced3869930626c38105d.tar.bz2
Fix reducers mutating the state instead of creating a new one
Diffstat (limited to 'packages/gitbook-core/src')
-rw-r--r--packages/gitbook-core/src/components/HTMLContent.js10
-rw-r--r--packages/gitbook-core/src/createReducer.js14
2 files changed, 20 insertions, 4 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;
};
}