ViewModelBase.Property<T> - observe_current uses delegate to get initial value, so it is always up-to-date

This commit is contained in:
John Colvin committed 2018-12-07 13:40:51 -06:00
1 parent bf290ec5c5
commit ae3fc51603
2 files changed
+7 -1

No files matched your search

@@ -317,6 +317,12 @@ namespace System.Reactive.Linq
public static async Task<(TResult result, bool success)> FirstAsyncTask<T, TResult>(this IObservable<T> source, Func<T, bool> predicate, Func<T, TResult> selector, TimeSpan timeout) where T : class =>
await source.Where(predicate).Select(val => (selector(val), true)).Merge(Observable.Return((default(TResult), false)).Delay(timeout)).FirstAsync();
public static IObservable<T> StartWith<T>(this IObservable<T> source, Func<T> get_value) =>
Observable.Create<T>(o => {
o.OnNext(get_value());
return source.Subscribe(o);
});
// This is placed here to intentionally make ObserveOnDispatcher ambiguous with the one provided by Rx
public static IObservable<T> ObserveOnDispatcher<T>(this IObservable<T> source) {
throw new InvalidOperationException("This method can starve the UI of input messages. Please use OnDispatcher() instead");
@@ -192,7 +192,7 @@ namespace mbts.ui.shell
public IObservable<T> observe_current(bool start_immediately = false) {
var source = this.Select(vals => vals.newval);
if (start_immediately)
source = source.StartWith(_value);
source = source.StartWith(() => _value);
return source;
}