Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit be987d5

Browse files
committed
Merge branch 'moduv5-improve-mapDispatchToProps'
2 parents 1f6a1b4 + bea90c1 commit be987d5

10 files changed

Lines changed: 13 additions & 116 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "snowflake",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"private": true,
55
"jest": {
66
"preset": "jest-react-native",

src/components/LoginRender.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,10 @@ var styles = StyleSheet.create({
102102
/**
103103
* ## Redux boilerplate
104104
*/
105-
const actions = [
106-
authActions,
107-
globalActions
108-
];
109105

110106
function mapDispatchToProps(dispatch) {
111-
const creators = Map()
112-
.merge(...actions)
113-
.filter(value => typeof value === 'function')
114-
.toObject();
115-
116107
return {
117-
actions: bindActionCreators(creators, dispatch),
118-
dispatch
108+
actions: bindActionCreators({ ...authActions, ...globalActions }, dispatch),
119109
};
120110
}
121111
/**

src/containers/App.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ from 'react-native';
4444
*/
4545
import Header from '../components/Header';
4646

47-
/**
48-
* ## Actions
49-
* 3 of our actions will be available as ```actions```
50-
*/
51-
const actions = [
52-
authActions,
53-
deviceActions,
54-
globalActions
55-
];
56-
5747
/**
5848
* Save that state
5949
*/
@@ -73,19 +63,11 @@ function mapStateToProps(state) {
7363
};
7464

7565
/**
76-
* Bind all the functions from the ```actions``` and bind them with
77-
* ```dispatch```
66+
* Bind all the actions from authActions, deviceActions and globalActions
7867
*/
7968
function mapDispatchToProps(dispatch) {
80-
81-
const creators = Map()
82-
.merge(...actions)
83-
.filter(value => typeof value === 'function')
84-
.toObject();
85-
8669
return {
87-
actions: bindActionCreators(creators, dispatch),
88-
dispatch
70+
actions: bindActionCreators({ ...authActions, ...deviceActions, ...globalActions }, dispatch),
8971
};
9072
}
9173

src/containers/ForgotPassword.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ const {
4040
/**
4141
* ## Redux boilerplate
4242
*/
43-
const actions = [
44-
authActions
45-
];
4643

4744
function mapStateToProps(state) {
4845
return {
@@ -52,14 +49,8 @@ function mapStateToProps(state) {
5249
}
5350

5451
function mapDispatchToProps(dispatch) {
55-
const creators = Map()
56-
.merge(...actions)
57-
.filter(value => typeof value === 'function')
58-
.toObject();
59-
6052
return {
61-
actions: bindActionCreators(creators, dispatch),
62-
dispatch
53+
actions: bindActionCreators(authActions, dispatch),
6354
};
6455
}
6556

src/containers/Login.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,8 @@ function mapStateToProps(state) {
5454
}
5555

5656
function mapDispatchToProps(dispatch) {
57-
const creators = Map()
58-
.merge(...actions)
59-
.filter(value => typeof value === 'function')
60-
.toObject();
61-
6257
return {
63-
actions: bindActionCreators(creators, dispatch),
64-
dispatch
58+
actions: bindActionCreators(authActions, dispatch),
6559
};
6660
}
6761

src/containers/Logout.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ var styles = StyleSheet.create({
5757
/**
5858
* ## Redux boilerplate
5959
*/
60-
const actions = [
61-
authActions,
62-
globalActions
63-
];
6460

6561
function mapStateToProps(state) {
6662
return {
@@ -78,14 +74,8 @@ function mapStateToProps(state) {
7874
};
7975

8076
function mapDispatchToProps(dispatch) {
81-
const creators = Map()
82-
.merge(...actions)
83-
.filter(value => typeof value === 'function')
84-
.toObject();
85-
8677
return {
87-
actions: bindActionCreators(creators, dispatch),
88-
dispatch
78+
actions: bindActionCreators({ ...authActions, ...globalActions }, dispatch),
8979
};
9080
}
9181
/**

src/containers/Main.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ from 'react-native';
4949
*/
5050
const Button = require('apsl-react-native-button');
5151

52-
53-
/**
54-
* Support for Hot reload
55-
*
56-
*/
57-
const actions = [
58-
authActions,
59-
globalActions
60-
];
61-
6252
/**
6353
* Instead of including all app states via ...state
6454
* One could explicitly enumerate only those which Main.js will depend on.
@@ -79,20 +69,11 @@ function mapStateToProps(state) {
7969
};
8070

8171
/*
82-
* Bind all the functions from the ```actions``` and bind them with
83-
* ```dispatch```
84-
72+
* Bind all the actions
8573
*/
8674
function mapDispatchToProps(dispatch) {
87-
88-
const creators = Map()
89-
.merge(...actions)
90-
.filter(value => typeof value === 'function')
91-
.toObject();
92-
9375
return {
94-
actions: bindActionCreators(creators, dispatch),
95-
dispatch
76+
actions: bindActionCreators({ ...authActions, ...globalActions }, dispatch),
9677
};
9778
}
9879

src/containers/Profile.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ var styles = StyleSheet.create({
8181
/**
8282
* ## Redux boilerplate
8383
*/
84-
const actions = [
85-
profileActions,
86-
globalActions
87-
];
8884

8985
function mapStateToProps(state) {
9086
return {
@@ -98,14 +94,8 @@ function mapStateToProps(state) {
9894
}
9995

10096
function mapDispatchToProps(dispatch) {
101-
const creators = Map()
102-
.merge(...actions)
103-
.filter(value => typeof value === 'function')
104-
.toObject();
105-
10697
return {
107-
actions: bindActionCreators(creators, dispatch),
108-
dispatch
98+
actions: bindActionCreators({ ...profileActions, ...globalActions }, dispatch),
10999
};
110100
}
111101
/**

src/containers/Register.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ const {
4141
/**
4242
* ## Redux boilerplate
4343
*/
44-
const actions = [
45-
authActions
46-
];
4744

4845
function mapStateToProps(state) {
4946
return {
@@ -53,14 +50,8 @@ function mapStateToProps(state) {
5350
}
5451

5552
function mapDispatchToProps(dispatch) {
56-
const creators = Map()
57-
.merge(...actions)
58-
.filter(value => typeof value === 'function')
59-
.toObject();
60-
6153
return {
62-
actions: bindActionCreators(creators, dispatch),
63-
dispatch
54+
actions: bindActionCreators(authActions, dispatch),
6455
};
6556
}
6657

src/containers/Subview.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ import * as deviceActions from '../reducers/device/deviceActions';
4949
/**
5050
* ## Redux boilerplate
5151
*/
52-
const actions = [
53-
deviceActions
54-
];
5552

5653
/**
5754
* Instead of including all app states via ...state
@@ -65,20 +62,11 @@ function mapStateToProps(state) {
6562
};
6663

6764
/*
68-
* Bind all the functions from the ```actions``` and bind them with
69-
* ```dispatch```
70-
65+
* Bind all the actions in deviceActions
7166
*/
7267
function mapDispatchToProps(dispatch) {
73-
74-
const creators = Map()
75-
.merge(...actions)
76-
.filter(value => typeof value === 'function')
77-
.toObject();
78-
7968
return {
80-
actions: bindActionCreators(creators, dispatch),
81-
dispatch
69+
actions: bindActionCreators(deviceActions, dispatch),
8270
};
8371
}
8472

0 commit comments

Comments
 (0)