void setupRx() { var scheduler = this.scheduler ?? RxApp.MainThreadScheduler; var countAsBehavior = Observable.Concat( Observable.Defer(() => Observable.Return(_NavigationStack.Count)), NavigationStack.CountChanged); NavigateBack = ReactiveCommand.CreateFromObservable(() => { NavigationStack.RemoveAt(NavigationStack.Count - 1); return(Observables.Unit); }, countAsBehavior.Select(x => x > 1), scheduler); Navigate = ReactiveCommand.CreateFromObservable <IRoutableViewModel, IRoutableViewModel>(x => { var vm = x as IRoutableViewModel; if (vm == null) { throw new Exception("Navigate must be called on an IRoutableViewModel"); } NavigationStack.Add(vm); return(Observable.Return(x)); }, outputScheduler: scheduler); NavigateAndReset = ReactiveCommand.CreateFromObservable <IRoutableViewModel, IRoutableViewModel>(x => { NavigationStack.Clear(); return(Navigate.Execute(x)); }, outputScheduler: scheduler); CurrentViewModel = Observable.Concat( Observable.Defer(() => Observable.Return(NavigationStack.LastOrDefault())), NavigationStack.Changed.Select(_ => NavigationStack.LastOrDefault())); }
public PullRequestDetailViewModel( IPullRequestService pullRequestsService, IPullRequestSessionManager sessionManager, IModelServiceFactory modelServiceFactory, IUsageTracker usageTracker, ITeamExplorerContext teamExplorerContext, IPullRequestFilesViewModel files, ISyncSubmodulesCommand syncSubmodulesCommand, IViewViewModelFactory viewViewModelFactory, IGitService gitService, IOpenIssueishDocumentCommand openDocumentCommand, [Import(AllowDefault = true)] JoinableTaskContext joinableTaskContext) { Guard.ArgumentNotNull(pullRequestsService, nameof(pullRequestsService)); Guard.ArgumentNotNull(sessionManager, nameof(sessionManager)); Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory)); Guard.ArgumentNotNull(usageTracker, nameof(usageTracker)); Guard.ArgumentNotNull(teamExplorerContext, nameof(teamExplorerContext)); Guard.ArgumentNotNull(syncSubmodulesCommand, nameof(syncSubmodulesCommand)); Guard.ArgumentNotNull(viewViewModelFactory, nameof(viewViewModelFactory)); Guard.ArgumentNotNull(gitService, nameof(gitService)); Guard.ArgumentNotNull(openDocumentCommand, nameof(openDocumentCommand)); this.pullRequestsService = pullRequestsService; this.sessionManager = sessionManager; this.modelServiceFactory = modelServiceFactory; this.usageTracker = usageTracker; this.teamExplorerContext = teamExplorerContext; this.syncSubmodulesCommand = syncSubmodulesCommand; this.viewViewModelFactory = viewViewModelFactory; this.gitService = gitService; this.openDocumentCommand = openDocumentCommand; JoinableTaskContext = joinableTaskContext ?? ThreadHelper.JoinableTaskContext; Files = files; Checkout = ReactiveCommand.CreateFromObservable( DoCheckout, this.WhenAnyValue(x => x.CheckoutState) .Cast <CheckoutCommandState>() .Select(x => x != null && x.IsEnabled)); Checkout.IsExecuting.Subscribe(x => isInCheckout = x); SubscribeOperationError(Checkout); Pull = ReactiveCommand.CreateFromObservable( DoPull, this.WhenAnyValue(x => x.UpdateState) .Cast <UpdateCommandState>() .Select(x => x != null && x.PullEnabled)); SubscribeOperationError(Pull); Push = ReactiveCommand.CreateFromObservable( DoPush, this.WhenAnyValue(x => x.UpdateState) .Cast <UpdateCommandState>() .Select(x => x != null && x.PushEnabled)); SubscribeOperationError(Push); SyncSubmodules = ReactiveCommand.CreateFromTask( DoSyncSubmodules, this.WhenAnyValue(x => x.UpdateState) .Cast <UpdateCommandState>() .Select(x => x != null && x.SyncSubmodulesEnabled)); SyncSubmodules.Subscribe(_ => Refresh().ToObservable()); SubscribeOperationError(SyncSubmodules); OpenConversation = ReactiveCommand.Create(DoOpenConversation); OpenOnGitHub = ReactiveCommand.Create(DoOpenDetailsUrl); ShowReview = ReactiveCommand.Create <IPullRequestReviewSummaryViewModel>(DoShowReview); ShowAnnotations = ReactiveCommand.Create <IPullRequestCheckViewModel>(DoShowAnnotations); }