-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReactiveUIExtensions
41 lines (39 loc) · 1.3 KB
/
ReactiveUIExtensions
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.Reactive.Linq;
using ReactiveUI;
using Splat;
namespace RxCheatsheet
{
public static class ReactiveUIExtensions
{
/// <summary>
/// Turns *view model* activation into an IObservable<bool> stream.
/// </summary>
/// <remarks>
// Credit: Kent Boogaart
// https://github.com/kentcb/YouIandReactiveUI
/// </remarks>
public static IObservable<bool> GetIsActivated(this ISupportsActivation @this) =>
Observable
.Merge(
@this.Activator.Activated.Select(_ => true),
@this.Activator.Deactivated.Select(_ => false))
.Replay(1)
.RefCount();
/// <summary>
/// Turns *view* activation into an IObservable<bool> stream.
/// </summary>
/// <remarks>
// Credit: Kent Boogaart
// https://github.com/kentcb/YouIandReactiveUI
/// </remarks>
public static IObservable<bool> GetIsActivated(this IActivatable @this)
{
var activationForViewFetcher = Locator.Current.GetService<IActivationForViewFetcher>();
return activationForViewFetcher
.GetActivationForView(@this)
.Replay(1)
.RefCount();
}
}
}