Last active
March 10, 2016 15:42
-
-
Save colinmeinke/6f578e8e8bf6c0d68e3e to your computer and use it in GitHub Desktop.
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 { updateId, updatePage, updateTags, getPosts, postsUpdating } from '../../actions'; | |
import { meta } from '../../config'; | |
const route = { | |
match: 'users/:id/posts', | |
title: state => `Blog of ${ state.user.name }`, | |
meta: state => [ | |
...meta, | |
{ name: 'description', content: state.user.description }, | |
], | |
onEnter: ( url, dispatch, getState, done ) => { | |
// Update redux store from url | |
// Would rely on batching middleware/enhancer | |
dispatch([ | |
updateUser( url.id ), | |
updatePage( url.page ), | |
updateTags( url.tags ), | |
postsUpdating(), | |
]); | |
const state = getState(); | |
// Do something with this new state | |
getPosts( state.user, state.page, state.tags ).then( action => { | |
dispatch( action ); | |
done(); | |
}); | |
}, | |
onExit: ( dispatch, getState, done ) => { | |
// Tidy up state | |
dispatch( updatePage()); | |
// Or hold off navigation until ready | |
checkDatabaseSynced().then( done ); | |
}, | |
}; | |
export default route; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment