-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ManualObservableSource experiments (see #21)
- Loading branch information
Showing
4 changed files
with
90 additions
and
20 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,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace TinkState.Internal | ||
{ | ||
class ManualObservableSource<T> : Dispatcher, Observable<T>, TinkState.ManualObservableSource<T>, DispatchingObservable<T> | ||
{ | ||
T value; | ||
|
||
public ManualObservableSource(T initialValue) | ||
{ | ||
value = initialValue; | ||
} | ||
|
||
public T Value => AutoObservable.Track(this); | ||
|
||
public Observable<T> Observe() | ||
{ | ||
return this; | ||
} | ||
|
||
public void Invalidate() | ||
{ | ||
Fire(); | ||
} | ||
|
||
public void Update(T newValue) | ||
{ | ||
value = newValue; | ||
Fire(); | ||
} | ||
|
||
public IDisposable Bind(Action<T> callback, IEqualityComparer<T> comparer = null, Scheduler scheduler = null) | ||
{ | ||
return new Binding<T>(this, callback, comparer, scheduler); | ||
} | ||
|
||
public Observable<TOut> Map<TOut>(Func<T, TOut> transform, IEqualityComparer<TOut> comparer = null) | ||
{ | ||
return new TransformObservable<T, TOut>(this, transform, comparer); | ||
} | ||
|
||
public IEqualityComparer<T> GetComparer() | ||
{ | ||
return NeverEqualityComparer<T>.Instance; | ||
} | ||
|
||
public long GetRevision() | ||
{ | ||
return revision; | ||
} | ||
|
||
public T GetCurrentValue() | ||
{ | ||
return value; | ||
} | ||
} | ||
} |
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,9 @@ | ||
namespace TinkState | ||
{ | ||
public interface ManualObservableSource<T> | ||
{ | ||
Observable<T> Observe(); | ||
void Invalidate(); | ||
void Update(T newValue); | ||
} | ||
} |
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