public void ReturnsFalseWhileExecuting() { var testScheduler = new TestScheduler(); var observer = testScheduler.CreateObserver <bool>(); var observable = testScheduler.CreateColdObservable( OnNext(10, "1"), OnNext(20, "2"), OnCompleted <string>(30) ); var action = new RxAction <Unit, string>(_ => observable, testScheduler); action.Enabled.Subscribe(observer); testScheduler.Schedule(TimeSpan.FromTicks(300), () => { action.Execute(Unit.Default); }); testScheduler.Start(); observer.Messages.AssertEqual( OnNext(0, true), OnNext(300, false), OnNext(331, true) ); }
private static IObservable <TOutput> executeSequentally <TInput, TOutput>(this RxAction <TInput, TOutput> action, IEnumerable <TInput> inputs) { var observables = inputs .Select(input => Observable.Defer(() => action.ExecuteWithCompletion(input))); return(Observable.Concat( observables )); }
public static void BindToAction <TInput, TOutput>(this UIButton button, RxAction <TInput, TOutput> action, Func <UIButton, TInput> transform) { button.Tapped() .Select(_ => transform(button)) .Subscribe(action.Inputs) .DisposedBy(action.DisposeBag); action.Enabled .Subscribe(e => { button.Enabled = e; }) .DisposedBy(action.DisposeBag); }
public static IDisposable BindAction <TInput, TOutput>( this IReactive <UIView> reactive, RxAction <TInput, TOutput> action, Func <TInput> transformationFunction) { return(Observable.Using( () => action.Enabled.Subscribe(e => { reactive.Base.UserInteractionEnabled = e; }), _ => reactive.Base.Rx().Tap().Select(unit => transformationFunction()) ) .Subscribe(action.Inputs)); }
public static IDisposable BindAction <TInput, TElement>(this IReactive <UISwitch> reactive, RxAction <TInput, TElement> action, Func <UISwitch, TInput> inputTransform) { IObservable <Unit> eventObservable = reactive.Base.Rx().Changed(); return(Observable.Using( () => action.Enabled.Subscribe(e => { reactive.Base.Enabled = e; }), _ => eventObservable ) .Select(_ => inputTransform(reactive.Base)) .Subscribe(action.Inputs)); }
public void ReturnsTheResultsOfTheOperation() { var testScheduler = new TestScheduler(); var observer = testScheduler.CreateObserver <string>(); var observable = testScheduler.CreateColdObservable( OnNext(10, "0"), OnNext(20, "1"), OnCompleted <string>(30) ); var action = new RxAction <Unit, string>(_ => observable, testScheduler); testScheduler.Schedule(TimeSpan.FromTicks(300), () => action.Execute(Unit.Default).Subscribe(observer)); testScheduler.Start(); observer.Messages.AssertEqual( OnNext(311, "0"), OnNext(321, "1"), OnCompleted <string>(331) ); }
public void ForwardsErrorsInTheExecution() { var testScheduler = new TestScheduler(); var exception = new Exception("This is an error"); var action = new RxAction <int, string>( i => Observable.Throw <string>(exception) ); var observer = testScheduler.CreateObserver <Exception>(); action.Errors.Subscribe(observer); testScheduler.Sleep(3); action.Execute(2); testScheduler.Start(); observer.Messages.AssertEqual( OnNext(3, exception) ); }
public override Task Initialize() { base.Initialize(); StartTimeEntry = rxActionFactory.FromObservable <Suggestion, IThreadSafeTimeEntry>(startTimeEntry); var appResumedFromBackground = backgroundService .AppResumedFromBackground .SelectUnit() .Skip(1); var userCalendarPreferencesChanged = userPreferences .EnabledCalendars .DistinctUntilChanged() .SelectUnit() .Skip(1); var syncingFinishedWhenInForeground = syncManager.ProgressObservable .Where(progress => progress != SyncProgress.Syncing && progress != SyncProgress.Unknown && !backgroundService.AppIsInBackground) .SelectUnit(); Suggestions = permissionsChecker.CalendarPermissionGranted .ReemitWhen(appResumedFromBackground) .ReemitWhen(userCalendarPreferencesChanged) .ReemitWhen(syncingFinishedWhenInForeground) .Throttle(recalculationThrottleDuration, schedulerProvider.BackgroundScheduler) .SelectMany(isCalendarAuthorized => getSuggestions() .Do(suggestions => trackPresentedSuggestions(suggestions, isCalendarAuthorized))) .DistinctUntilChanged(suggestionsComparer) .Do(widgetsService.OnSuggestionsUpdated) .ObserveOn(schedulerProvider.BackgroundScheduler) .AsDriver(onErrorJustReturn: ImmutableList.Create <Suggestion>(), schedulerProvider: schedulerProvider); IsEmpty = Suggestions .Select(suggestions => suggestions.None()) .StartWith(true) .AsDriver(onErrorJustReturn: true, schedulerProvider: schedulerProvider); return(base.Initialize()); }
public void ReturnsTheResultsOfTheOperation() { var testScheduler = new TestScheduler(); var action = new RxAction <int, string>( i => Observable.Interval(TimeSpan.FromTicks(1), testScheduler) .Take(i) .Select(l => l.ToString()) ); var observer = testScheduler.CreateObserver <string>(); testScheduler.Sleep(3); action.Execute(2).Subscribe(observer); testScheduler.Start(); observer.Messages.AssertEqual( OnNext(4, "0"), OnNext(5, "1"), OnCompleted <string>(5) ); }
public void ForwardsErrorsInTheExecution() { var testScheduler = new TestScheduler(); var exception = new Exception("This is an error"); var observable = testScheduler.CreateColdObservable( OnError <string>(10, exception) ); var action = new RxAction <Unit, string>(_ => observable, testScheduler); var observer = testScheduler.CreateObserver <Exception>(); action.Errors.Subscribe(observer); testScheduler.Schedule(TimeSpan.FromTicks(300), () => action.Execute(Unit.Default)); testScheduler.Start(); observer.Messages.AssertEqual( OnNext(311, exception) ); }
public static IDisposable BindAction <TInput, TElement>(this IReactive <UIButton> reactive, RxAction <TInput, TElement> action, Func <UIButton, TInput> inputTransform, ButtonEventType eventType = ButtonEventType.Tap, bool useFeedback = false) { IObservable <Unit> eventObservable = Observable.Empty <Unit>(); switch (eventType) { case ButtonEventType.Tap: eventObservable = reactive.Base.Rx().Tap(); break; case ButtonEventType.LongPress: eventObservable = reactive.Base.Rx().LongPress(useFeedback); break; } return(Observable.Using( () => action.Enabled.Subscribe(e => { reactive.Base.Enabled = e; }), _ => eventObservable ) .Select(_ => inputTransform(reactive.Base)) .Subscribe(action.Inputs)); }
public override Task Initialize() { base.Initialize(); StartTimeEntry = rxActionFactory.FromObservable <Suggestion, IThreadSafeTimeEntry>(startTimeEntry); var appResumedFromBackground = backgroundService .AppResumedFromBackground .SelectUnit() .Skip(1); var userCalendarPreferencesChanged = userPreferences .EnabledCalendars .SelectUnit() .Skip(1); Suggestions = syncManager.ProgressObservable .Where(progress => progress != SyncProgress.Syncing && progress != SyncProgress.Unknown && !backgroundService.AppIsInBackground) .Throttle(recalculationThrottleDuration, schedulerProvider.DefaultScheduler) .SelectUnit() .StartWith(Unit.Default) .Merge(recalculationRequested) .Merge(appResumedFromBackground) .Merge(userCalendarPreferencesChanged) .SelectMany(_ => getSuggestions()) .WithLatestFrom(permissionsChecker.CalendarPermissionGranted, (suggestions, isCalendarAuthorized) => (suggestions, isCalendarAuthorized)) .Do(item => trackPresentedSuggestions(item.suggestions, item.isCalendarAuthorized)) .Select(item => item.suggestions) .AsDriver(onErrorJustReturn: ImmutableList.Create <Suggestion>(), schedulerProvider: schedulerProvider); IsEmpty = Suggestions .Select(suggestions => suggestions.None()) .StartWith(true) .AsDriver(onErrorJustReturn: true, schedulerProvider: schedulerProvider); return(base.Initialize()); }
public void ReturnsFalseWhileExecuting() { var testScheduler = new TestScheduler(); var action = new RxAction <int, string>( i => Observable.Interval(TimeSpan.FromTicks(1), testScheduler) .Take(i) .Select(l => l.ToString()) ); var observer = testScheduler.CreateObserver <bool>(); action.Enabled.Subscribe(observer); testScheduler.Sleep(3); action.Execute(2); testScheduler.Start(); observer.Messages.AssertEqual( OnNext(0, true), OnNext(3, false), OnNext(5, true) ); }
public static IObservable <Unit> PrependAction <TInput>(this IObservable <Unit> observable, RxAction <TInput, Unit> action, TInput input) => observable.prependAction(action, input);
public static IObservable <Unit> PrependAction(this IObservable <Unit> observable, RxAction <Unit, Unit> action) => observable.prependAction(action, default(Unit));
public static IDisposable BindTapAction <TElement>(this IReactive <UISwitch> reactive, RxAction <Unit, TElement> action) => reactive.BindAction(action, _ => Unit.Default);
public RxAction <TInput, TElement> FromAsync <TInput, TElement>(Func <TInput, Task <TElement> > asyncAction, IObservable <bool> enabledIf = null) { return(RxAction <TInput, TElement> .FromAsync(asyncAction, schedulerProvider.MainScheduler, enabledIf)); }
public static void BindToAction <TOutput>(this UIButton button, RxAction <Unit, TOutput> action) { button.BindToAction(action, Unit.Default); }
public static void BindToAction <TInput, TOutput>(this UIButton button, RxAction <TInput, TOutput> action, TInput input) { button.BindToAction(action, _ => input); }
public static void BindToAction <TInput, TOutput>(this IReactive <UIButton> reactive, RxAction <TInput, TOutput> action, TInput input) { reactive.BindToAction(action, _ => input); }
public static void BindToAction <TOutput>(this IReactive <UIButton> reactive, RxAction <Unit, TOutput> action) { reactive.BindToAction(action, Unit.Default); }
private static IObservable <TOutput> prependAction <TElement, TInput, TOutput>(this IObservable <TElement> observable, RxAction <TInput, TOutput> action, TInput input) { return(observable .SelectValue(default(TOutput)) .IgnoreElements() .Concat( Observable.Defer(() => action.ExecuteWithCompletion(input)) )); }
public RxAction <TInput, TElement> FromFunction <TInput, TElement>(Func <TInput, TElement> action) { return(RxAction <TInput, TElement> .FromFunction(action, schedulerProvider.MainScheduler)); }
public static IObservable <TOutput> ExecuteSequentally <TInput, TOutput>(this RxAction <TInput, TOutput> action, IEnumerable <TInput> inputs) => action.executeSequentally(inputs);
public RxAction <TInput, TElement> FromObservable <TInput, TElement>(Func <TInput, IObservable <TElement> > workFactory, IObservable <bool> enabledIf = null) { return(RxAction <TInput, TElement> .FromObservable(workFactory, schedulerProvider.MainScheduler, enabledIf)); }
public static IObservable <TOutput> ExecuteSequentally <TInput, TOutput>(this RxAction <TInput, TOutput> action, params TInput[] inputs) => action.executeSequentally(inputs);
public static IDisposable BindAction <TElement>(this IReactive <UIButton> reactive, RxAction <Unit, TElement> action, ButtonEventType eventType = ButtonEventType.Tap) => reactive.BindAction(action, _ => Unit.Default, eventType);
public static IObservable <Unit> ExecuteSequentally(this RxAction <Unit, Unit> action, int times) => action.executeSequentally(Enumerable.Range(0, times).Select(_ => default(Unit)));
public static void Bind <TInput, TOutput>(this IReactiveBindingHolder holder, IObservable <TInput> observable, RxAction <TInput, TOutput> action) { observable .Subscribe(action.Inputs) .DisposedBy(holder.DisposeBag); }
public static IDisposable BindToggleAction <TElement>(this IReactive <UISwitch> reactive, RxAction <bool, TElement> action) => reactive.BindAction(action, s => s.On);