diff --git a/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs b/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs index b72c43513..a5cc7ca5c 100644 --- a/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs +++ b/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs @@ -317,6 +317,12 @@ namespace System.Reactive.Linq public static async Task<(TResult result, bool success)> FirstAsyncTask(this IObservable source, Func predicate, Func 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 StartWith(this IObservable source, Func get_value) => + Observable.Create(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 ObserveOnDispatcher(this IObservable source) { throw new InvalidOperationException("This method can starve the UI of input messages. Please use OnDispatcher() instead"); diff --git a/src/client/spark/core/Utility/ViewModelBase.cs b/src/client/spark/core/Utility/ViewModelBase.cs index d2040d3b1..542ec5d1f 100644 --- a/src/client/spark/core/Utility/ViewModelBase.cs +++ b/src/client/spark/core/Utility/ViewModelBase.cs @@ -192,7 +192,7 @@ namespace mbts.ui.shell public IObservable 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; }