public static IDisposable BindTo(this ReactiveCommand <Unit> command, Button button) { IDisposable disposable = command.CanExecute.SubscribeToInteractable(button); IDisposable disposable2 = button.OnClickAsObservable().SubscribeWithState(command, delegate(Unit x, ReactiveCommand <Unit> c) { c.Execute(x); }); return(StableCompositeDisposable.Create(disposable, disposable2)); }
public static IDisposable BindToOnClick(this AsyncReactiveCommand <Unit> command, Button button, Func <Unit, IObservable <Unit> > asyncOnClick) { IDisposable disposable = command.CanExecute.SubscribeToInteractable(button); IDisposable disposable2 = button.OnClickAsObservable().SubscribeWithState(command, delegate(Unit x, AsyncReactiveCommand <Unit> c) { c.Execute(x); }); IDisposable disposable3 = command.Subscribe(asyncOnClick); return(StableCompositeDisposable.Create(disposable, disposable2, disposable3)); }
static AsyncSubject<TSource> RunAsync<TSource>(IConnectableObservable<TSource> source, CancellationToken cancellationToken) { var s = new AsyncSubject<TSource>(); if (cancellationToken.IsCancellationRequested) { return Cancel(s, cancellationToken); } var d = source.Subscribe(s); var c = source.Connect(); if (cancellationToken.CanBeCanceled) { RegisterCancelation(s, StableCompositeDisposable.Create(d, c), cancellationToken); } return s; }
// for uGUI(from 4.6) /// <summary> /// Bind ReactiveCommand to button's interactable and onClick. /// </summary> public static IDisposable BindTo(this IReactiveCommand<Unit> command, UnityEngine.UI.Button button) { var d1 = command.CanExecute.SubscribeToInteractable(button); var d2 = button.OnClickAsObservable().SubscribeWithState(command, (x, c) => c.Execute(x)); return StableCompositeDisposable.Create(d1, d2); }