Skip to content

Commit 7843d75

Browse files
committed
Added mergeProps function to connect
1 parent 5efacca commit 7843d75

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,17 @@ function mapActionToProps(dispatch) {
102102
data: { todo }
103103
})
104104
}
105-
}
105+
};
106+
}
107+
108+
function mergeProps(stateProps, actionsProps) {
109+
return {
110+
...stateProps,
111+
...actionsProps,
112+
};
106113
}
107114

108-
export default connect(mapStateToProps, mapActionToProps)(App);
115+
export default connect(mapStateToProps, mapActionToProps, mergeProps)(App);
109116

110117
```
111118

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-vue",
3-
"version": "0.7.1",
3+
"version": "0.8.1",
44
"description": "Vue Redux binding higher order component",
55
"author": "Nadim Tuhin",
66
"repository": {

src/connect.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ function getProps(component) {
4444
};
4545
}
4646

47+
function defaultMergeProps(stateProps, actionsProps) {
48+
return {
49+
...stateProps,
50+
...actionsProps,
51+
};
52+
}
53+
4754
/**
4855
* 1. utilities are moved above because vue stores methods, states and props
4956
* in the same namespace
@@ -53,11 +60,13 @@ function getProps(component) {
5360
/**
5461
* @param mapStateToProps
5562
* @param mapActionsToProps
63+
* @param mergeProps
5664
* @returns Object
5765
*/
58-
export default function connect(mapStateToProps, mapActionsToProps) {
66+
export default function connect(mapStateToProps, mapActionsToProps, mergeProps) {
5967
mapStateToProps = mapStateToProps || noop;
6068
mapActionsToProps = mapActionsToProps || noop;
69+
mergeProps = mergeProps || defaultMergeProps;
6170

6271
return (children) => {
6372

@@ -90,8 +99,7 @@ export default function connect(mapStateToProps, mapActionsToProps) {
9099
const actionNames = Object.keys(actions);
91100

92101
return {
93-
...state,
94-
...actions,
102+
...mergeProps(state, actions),
95103
vuaReduxStateNames: stateNames,
96104
vuaReduxActionNames: actionNames
97105
};

0 commit comments

Comments
 (0)