Get router history working with flux

This commit is contained in:
Berkeley Martinez
2015-12-31 17:39:29 -08:00
parent dcf7f59667
commit 80d36cc3cd
5 changed files with 117 additions and 53 deletions

View File

@@ -38,8 +38,14 @@ export default Actions({
});
},
updateRoute(route) {
return { route };
},
goBack: null
// routing
goTo: null,
goBack: null,
updateLocation(location) {
return {
transform(state) {
return { ...state, location };
}
};
}
});

View File

@@ -20,7 +20,12 @@ export default Store({
value: initValue
},
init({ instance: appStore, args: [cat] }) {
const { updateRoute, getUser, setTitle } = cat.getActions('appActions');
const {
updateLocation,
getUser,
setTitle
} = cat.getActions('appActions');
const register = createRegistrar(appStore);
const {
toggleQuestions,
@@ -33,7 +38,17 @@ export default Store({
} = cat.getActions('hikesActions');
// app
register(setter(fromMany(getUser, setTitle, updateRoute)));
register(
fromMany(
setter(
fromMany(
getUser,
setTitle
)
),
updateLocation
)
);
// hikes
register(

View File

@@ -218,9 +218,12 @@ export default Actions({
const currentHike = findNextHike(hikes, id);
// go to next route
state.route = currentHike && currentHike.dashedName ?
`/hikes/${ currentHike.dashedName }` :
'/hikes';
state.location = {
action: 'PUSH',
pathname: currentHike && currentHike.dashedName ?
`/hikes/${ currentHike.dashedName }` :
'/hikes'
};
const hikesApp = {
...state.hikesApp,