Exemplo n.º 1
0
        public static IObservable <T> ObservableFromPool <T, TViewModel>(
            this TViewModel viewModel,
            Func <IObservable <T> > observableFactory,
            IScheduler scheduler,
            [CallerMemberName] string name = null,
            bool longSubscription          = false) where TViewModel : IViewModel, IBindable
        {
            var observable = viewModel.GetValue(() =>
            {
                var subscriptions = longSubscription ? viewModel.LongDisposables : viewModel.ShortDisposables;
                var obs           = observableFactory();
                var subject       = new ReplaySubject <T>(1, scheduler);
                subject.DisposeWith(subscriptions);
                obs.Subscribe(subject).DisposeWith(subscriptions);
                return(subject.AsObservable());
            }, name);

            return(observable);
        }