Skip to content

Commit

Permalink
Merge branch 'moduv5-improve-mapDispatchToProps'
Browse files Browse the repository at this point in the history
  • Loading branch information
bartonhammond committed Aug 18, 2016
2 parents 1f6a1b4 + bea90c1 commit be987d5
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 116 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snowflake",
"version": "0.1.6",
"version": "0.1.7",
"private": true,
"jest": {
"preset": "jest-react-native",
Expand Down
12 changes: 1 addition & 11 deletions src/components/LoginRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,10 @@ var styles = StyleSheet.create({
/**
* ## Redux boilerplate
*/
const actions = [
authActions,
globalActions
];

function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();

return {
actions: bindActionCreators(creators, dispatch),
dispatch
actions: bindActionCreators({ ...authActions, ...globalActions }, dispatch),
};
}
/**
Expand Down
22 changes: 2 additions & 20 deletions src/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ from 'react-native';
*/
import Header from '../components/Header';

/**
* ## Actions
* 3 of our actions will be available as ```actions```
*/
const actions = [
authActions,
deviceActions,
globalActions
];

/**
* Save that state
*/
Expand All @@ -73,19 +63,11 @@ function mapStateToProps(state) {
};

/**
* Bind all the functions from the ```actions``` and bind them with
* ```dispatch```
* Bind all the actions from authActions, deviceActions and globalActions
*/
function mapDispatchToProps(dispatch) {

const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();

return {
actions: bindActionCreators(creators, dispatch),
dispatch
actions: bindActionCreators({ ...authActions, ...deviceActions, ...globalActions }, dispatch),
};
}

Expand Down
11 changes: 1 addition & 10 deletions src/containers/ForgotPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ const {
/**
* ## Redux boilerplate
*/
const actions = [
authActions
];

function mapStateToProps(state) {
return {
Expand All @@ -52,14 +49,8 @@ function mapStateToProps(state) {
}

function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();

return {
actions: bindActionCreators(creators, dispatch),
dispatch
actions: bindActionCreators(authActions, dispatch),
};
}

Expand Down
8 changes: 1 addition & 7 deletions src/containers/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,8 @@ function mapStateToProps(state) {
}

function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();

return {
actions: bindActionCreators(creators, dispatch),
dispatch
actions: bindActionCreators(authActions, dispatch),
};
}

Expand Down
12 changes: 1 addition & 11 deletions src/containers/Logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ var styles = StyleSheet.create({
/**
* ## Redux boilerplate
*/
const actions = [
authActions,
globalActions
];

function mapStateToProps(state) {
return {
Expand All @@ -78,14 +74,8 @@ function mapStateToProps(state) {
};

function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();

return {
actions: bindActionCreators(creators, dispatch),
dispatch
actions: bindActionCreators({ ...authActions, ...globalActions }, dispatch),
};
}
/**
Expand Down
23 changes: 2 additions & 21 deletions src/containers/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ from 'react-native';
*/
const Button = require('apsl-react-native-button');


/**
* Support for Hot reload
*
*/
const actions = [
authActions,
globalActions
];

/**
* Instead of including all app states via ...state
* One could explicitly enumerate only those which Main.js will depend on.
Expand All @@ -79,20 +69,11 @@ function mapStateToProps(state) {
};

/*
* Bind all the functions from the ```actions``` and bind them with
* ```dispatch```
* Bind all the actions
*/
function mapDispatchToProps(dispatch) {

const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();

return {
actions: bindActionCreators(creators, dispatch),
dispatch
actions: bindActionCreators({ ...authActions, ...globalActions }, dispatch),
};
}

Expand Down
12 changes: 1 addition & 11 deletions src/containers/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ var styles = StyleSheet.create({
/**
* ## Redux boilerplate
*/
const actions = [
profileActions,
globalActions
];

function mapStateToProps(state) {
return {
Expand All @@ -98,14 +94,8 @@ function mapStateToProps(state) {
}

function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();

return {
actions: bindActionCreators(creators, dispatch),
dispatch
actions: bindActionCreators({ ...profileActions, ...globalActions }, dispatch),
};
}
/**
Expand Down
11 changes: 1 addition & 10 deletions src/containers/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ const {
/**
* ## Redux boilerplate
*/
const actions = [
authActions
];

function mapStateToProps(state) {
return {
Expand All @@ -53,14 +50,8 @@ function mapStateToProps(state) {
}

function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();

return {
actions: bindActionCreators(creators, dispatch),
dispatch
actions: bindActionCreators(authActions, dispatch),
};
}

Expand Down
16 changes: 2 additions & 14 deletions src/containers/Subview.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ import * as deviceActions from '../reducers/device/deviceActions';
/**
* ## Redux boilerplate
*/
const actions = [
deviceActions
];

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

/*
* Bind all the functions from the ```actions``` and bind them with
* ```dispatch```
* Bind all the actions in deviceActions
*/
function mapDispatchToProps(dispatch) {

const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();

return {
actions: bindActionCreators(creators, dispatch),
dispatch
actions: bindActionCreators(deviceActions, dispatch),
};
}

Expand Down

0 comments on commit be987d5

Please sign in to comment.