Skip to content

Commit ec161e3

Browse files
committed
Move Navigate commands to be earlier so they aren't scheduled. Fixes #761
1 parent 6470494 commit ec161e3

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

ReactiveUI/RoutingState.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,26 @@ void setupRx()
7474
Observable.Defer(() => Observable.Return(_NavigationStack.Count)),
7575
NavigationStack.CountChanged);
7676

77-
NavigateBack = ReactiveCommand.CreateAsyncObservable(
78-
countAsBehavior.Select(x => x > 1),
79-
_ => Observable.Return(Unit.Default));
80-
81-
NavigateBack.Subscribe(_ =>
82-
NavigationStack.RemoveAt(NavigationStack.Count - 1));
77+
NavigateBack = ReactiveCommand.CreateAsyncObservable (countAsBehavior.Select (x => x > 1), _ => {
78+
NavigationStack.RemoveAt(NavigationStack.Count - 1);
79+
return Observable.Return(Unit.Default);
80+
});
8381

84-
Navigate = new ReactiveCommand<object>(Observable.Return(true), x => Observable.Return(x));
85-
Navigate.Subscribe(x => {
82+
Navigate = new ReactiveCommand<object>(Observable.Return(true), x => {
8683
var vm = x as IRoutableViewModel;
8784
if (vm == null) {
8885
throw new Exception("Navigate must be called on an IRoutableViewModel");
8986
}
9087

9188
NavigationStack.Add(vm);
89+
return Observable.Return(x);
9290
});
9391

94-
NavigateAndReset = new ReactiveCommand<object>(Observable.Return(true), x => Observable.Return(x));
95-
NavigateAndReset
96-
.SelectMany(x => {
97-
NavigationStack.Clear();
98-
return Navigate.ExecuteAsync(x);
99-
}).Subscribe();
100-
92+
NavigateAndReset = new ReactiveCommand<object> (Observable.Return (true), x => {
93+
NavigationStack.Clear();
94+
return Navigate.ExecuteAsync(x);
95+
});
96+
10197
CurrentViewModel = Observable.Concat(
10298
Observable.Defer(() => Observable.Return(NavigationStack.LastOrDefault())),
10399
NavigationStack.Changed.Select(_ => NavigationStack.LastOrDefault()));

0 commit comments

Comments
 (0)