generated from nventive/Template
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSectionNavigatorExtensions.cs
More file actions
41 lines (38 loc) · 1.48 KB
/
SectionNavigatorExtensions.cs
File metadata and controls
41 lines (38 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Text;
using Chinook.SectionsNavigation;
using Chinook.StackNavigation;
namespace Chinook.SectionsNavigation;
public static class SectionNavigatorExtensions
{
/// <summary>
/// Gets an observable of the last page type from currently active section.
/// The observable pushes a value whenever a navigation request is processed with the type of the last page ViewModel.
/// </summary>
/// <param name="sectionsNavigator">The sections navigator.</param>
/// <returns>An observable of types.</returns>
public static IObservable<Type> ObserveActiveSectionLastPageType(this ISectionsNavigator sectionsNavigator)
{
return sectionsNavigator
.ObserveStateChanged()
.Where(args => args.EventArgs.CurrentState.LastRequestState == NavigatorRequestState.Processed)
.Select(args =>
{
var state = args.EventArgs.CurrentState;
return state.ActiveSection?.State.Stack.LastOrDefault()?.ViewModel.GetType();
})
.StartWith(sectionsNavigator.State.ActiveSection?.State.Stack.LastOrDefault()?.ViewModel.GetType());
}
public static IObservable<SectionsNavigatorEventArgs> ObserveProcessedState(this ISectionsNavigator sectionsNavigator)
{
return sectionsNavigator
.ObserveStateChanged()
.Where(args => args.EventArgs.CurrentState.LastRequestState == NavigatorRequestState.Processed)
.Select(args => args.EventArgs);
}
}