Skip to content

Instantly share code, notes, and snippets.

@carlosble
Last active January 12, 2018 20:05
Show Gist options
  • Save carlosble/613f5a1e0d997eac8855a852c467cf86 to your computer and use it in GitHub Desktop.
Save carlosble/613f5a1e0d997eac8855a852c467cf86 to your computer and use it in GitHub Desktop.
Factory in a Redux App
import {connect} from 'react-redux';
import {ProfilePage as OriginalProfilePage} from './containers/ProfilePage';
import createServerApi from './utils/serverApi';
import * as profileActions from './actions/profileActions';
import notifier from './utils/notifications';
export const createProfilePage = (serverApi, notifier) => {
return connect(
(state) => {
return {
profile: state.profile,
notifier: notifier
};
},
(dispatch) => ({
actions: {
loadProfile: () => {
return dispatch(profileActions.loadProfile(serverApi));
},
saveProfile: (profile) => {
return profileActions.saveProfile(profile, serverApi);
}, ,
changeProfile: (name, value) => {
return dispatch(profileActions.changeProfile(name, value));
}
}
})
)(OriginalProfilePage);
};
export const ProfilePage = createProfilePage(createServerApi(), notifier());
@corlaez
Copy link

corlaez commented Jan 12, 2018

It would help a lot readers to have a mapStateToProps and mapDispatchToProps defined, the code is too nested IMHO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment