Fix issue with transitioning between routes
This commit is contained in:
@@ -22,6 +22,19 @@ const history = createHistory();
|
||||
const appLocation = createLocation(
|
||||
location.pathname + location.search
|
||||
);
|
||||
|
||||
function location$(history) {
|
||||
return Rx.Observable.create(function(observer) {
|
||||
const dispose = history.listen(function(location) {
|
||||
observer.onNext(location.pathname);
|
||||
});
|
||||
|
||||
return Rx.Disposable.create(() => {
|
||||
dispose();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// returns an observable
|
||||
app$({ history, location: appLocation })
|
||||
.flatMap(
|
||||
@@ -37,18 +50,25 @@ app$({ history, location: appLocation })
|
||||
({ nextLocation, props }, appCat) => ({ nextLocation, props, appCat })
|
||||
)
|
||||
.doOnNext(({ appCat }) => {
|
||||
const appStore = appCat.getStore('appStore');
|
||||
const appActions = appCat.getActions('appActions');
|
||||
|
||||
appStore
|
||||
location$(history)
|
||||
.pluck('pathname')
|
||||
.distinctUntilChanged()
|
||||
.subscribe(function({ route = appLocation.pathname }) {
|
||||
history.pushState(null, route);
|
||||
});
|
||||
.doOnNext(route => debug('route change', route))
|
||||
.subscribe(route => appActions.updateRoute(route));
|
||||
|
||||
appActions.goBack.subscribe(function() {
|
||||
history.goBack();
|
||||
});
|
||||
|
||||
appActions
|
||||
.updateRoute
|
||||
.pluck('route')
|
||||
.doOnNext(route => debug('update route', route))
|
||||
.subscribe(function(route) {
|
||||
history.pushState(null, route);
|
||||
});
|
||||
})
|
||||
.flatMap(({ props, appCat }) => {
|
||||
props.history = history;
|
||||
@@ -63,7 +83,7 @@ app$({ history, location: appLocation })
|
||||
debug('react rendered');
|
||||
},
|
||||
err => {
|
||||
debug('an error has occured', err.stack);
|
||||
throw err;
|
||||
},
|
||||
() => {
|
||||
debug('react closed subscription');
|
||||
|
Reference in New Issue
Block a user