Last active
January 12, 2018 20:05
-
-
Save carlosble/613f5a1e0d997eac8855a852c467cf86 to your computer and use it in GitHub Desktop.
Factory in a Redux App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would help a lot readers to have a mapStateToProps and mapDispatchToProps defined, the code is too nested IMHO.