-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates dependencies and some cleanups
- Loading branch information
Showing
4 changed files
with
63 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
|
||
namespace Leayal.SnowBreakLauncher.Classes | ||
{ | ||
static class ObservableExtensions | ||
{ | ||
sealed class Stub_OnTargetPropChanged<T> : IObserver<T> | ||
{ | ||
public readonly Action<T> _onTargetPropChanged; | ||
private T? lastValue; | ||
|
||
public Stub_OnTargetPropChanged(Action<T> onTargetPropChanged) | ||
{ | ||
this._onTargetPropChanged = onTargetPropChanged; | ||
this.lastValue = default; | ||
} | ||
|
||
public void OnCompleted() | ||
{ | ||
// Do nothing | ||
} | ||
|
||
public void OnError(Exception error) | ||
{ | ||
// Do nothing | ||
} | ||
|
||
public void OnNext(T value) | ||
{ | ||
if (!EqualityComparer<T>.Default.Equals(this.lastValue, value)) | ||
{ | ||
this.lastValue = value; | ||
this._onTargetPropChanged(value); | ||
} | ||
} | ||
} | ||
|
||
public static IDisposable Subscribe<T>(this IObservable<T> observable, Action<T> onTargetPropChanged) | ||
{ | ||
var obj = new Stub_OnTargetPropChanged<T>(onTargetPropChanged); | ||
return observable.Subscribe(obj); | ||
} | ||
|
||
public static void Subscribe<T>(this IObservable<T> observable, Action<T> onTargetPropChanged, CancellationToken cancellationToken) | ||
{ | ||
var canceller = Subscribe(observable, onTargetPropChanged); | ||
if (cancellationToken.CanBeCanceled) | ||
{ | ||
cancellationToken.Register(canceller.Dispose); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters