public ObservablesListItem(IConcurrencyService concurrencyService)
        {
            mSubscriptionCount = ObservableAsPropertyHelper <int> .Default();

            this.WhenActivated((CompositeDisposable disposables) =>
            {
                var subCount = ObservableInstance.Subscriptions
                               .Publish(subs => subs
                                        .ToObservableChangeSet(sub => sub.SubscriptionId)
                                        .Merge(subs.SelectMany(sub => sub.Events
                                                               .TakeUntil(e => e.Kind == OnCompleted || e.Kind == OnError || e.Kind == Unsubscribe)
                                                               .WhenTerminated()
                                                               .Select(_ => new Change <ISubscription, long>(ChangeReason.Remove, sub.SubscriptionId, sub))
                                                               .Select(chg => new ChangeSet <ISubscription, long> {
                    chg
                }))))
                               .AsObservableCache()
                               .CountChanged
                               .TakeUntilDisposed(disposables)
                               .SubscribeOn(concurrencyService.TaskPoolRxScheduler)
                               .ObserveOn(concurrencyService.DispatcherRxScheduler)
                               .Publish();

                subCount
                .ToProperty(this, x => x.SubscriptionCount, out mSubscriptionCount)
                .DisposeWith(disposables);

                subCount.Connect();
            });
        }
Example #2
0
        public ViewModelBase(INavigationService navigationService)
        {
            NavigationService = navigationService;

            _isBusy = ObservableAsPropertyHelper <bool> .Default(false);

            _isNotBusy = this.WhenAnyValue(x => x.IsBusy)
                         .Select(x => !IsBusy)
                         .ToProperty(this, x => x.IsNotBusy, true);

            //Set indicator visibility based on IsBusy
            this.WhenAnyValue(x => x.IsBusy).Subscribe(async _ => { await SetIndictorState(true); });
            this.WhenAnyValue(x => x.IsNotBusy).Subscribe(async _ => { await SetIndictorState(false); });

            var canExecute = this.WhenAnyValue(x => x.IsNotBusy);

            AddIsBusyObservable(this.WhenAnyObservable(x => x.ExternalBrowseCommand.IsExecuting));
        }