Skip to content
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

feat(connector): allow override of stateSliceEqualityComparer #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"plugins": "transform-runtime",
"env": {
"test": {
"presets": ["env"]
"presets": ["env"],
"plugins": "transform-object-rest-spread"
}
}
}
202 changes: 117 additions & 85 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@commitlint/cli": "^5.2.8",
"@commitlint/config-conventional": "^5.2.3",
"babel-core": "^6.25.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"cross-env": "^5.0.5",
Expand All @@ -53,7 +54,7 @@
"rollup-plugin-node-resolve": "^3.0.2",
"rollup-plugin-replace": "2.0.0",
"rollup-plugin-uglify": "^3.0.0",
"sinon": "^3.2.0",
"sinon": "^7.5.0",
"standard-version": "^4.2.0"
},
"dependencies": {
Expand Down
7 changes: 4 additions & 3 deletions src/components/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const defaultMapStateToTarget = () => ({});
const defaultMapDispatchToTarget = dispatch => ({dispatch});

export default function Connector(store) {
return (mapStateToTarget, mapDispatchToTarget) => {
return (mapStateToTarget, mapDispatchToTarget, stateSliceEqualityComparer = null) => {

let finalMapStateToTarget = mapStateToTarget || defaultMapStateToTarget;

let finalStateSliceEqualityComparer = stateSliceEqualityComparer || shallowEqual;
const finalMapDispatchToTarget = isObject(mapDispatchToTarget) && !isFunction(mapDispatchToTarget) ?
wrapActionCreators(mapDispatchToTarget) :
mapDispatchToTarget || defaultMapDispatchToTarget;
Expand Down Expand Up @@ -51,7 +51,8 @@ export default function Connector(store) {

const unsubscribe = store.subscribe(() => {
const nextSlice = getStateSlice(store.getState(), finalMapStateToTarget);
if (!shallowEqual(slice, nextSlice)) {
const shouldUpdateTarget = !finalStateSliceEqualityComparer(slice, nextSlice);
if (shouldUpdateTarget) {
updateTarget(target, nextSlice, boundActionCreators, slice);
slice = nextSlice;
}
Expand Down
Loading