|
13 | 13 | using GitHub.Extensions;
|
14 | 14 | using NullGuard;
|
15 | 15 | using GitHub.App;
|
| 16 | +using System.Reactive.Subjects; |
| 17 | +using System.Reactive; |
| 18 | +using System.Diagnostics.CodeAnalysis; |
16 | 19 | using Octokit;
|
17 | 20 |
|
18 | 21 | namespace GitHub.ViewModels
|
19 | 22 | {
|
20 | 23 | [ExportViewModel(ViewType = UIViewType.PRCreation)]
|
21 | 24 | [PartCreationPolicy(CreationPolicy.NonShared)]
|
| 25 | + [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable")] |
22 | 26 | public class PullRequestCreationViewModel : BaseViewModel, IPullRequestCreationViewModel
|
23 | 27 | {
|
24 | 28 | readonly IRepositoryHost repositoryHost;
|
25 | 29 | readonly ISimpleRepositoryModel activeRepo;
|
| 30 | + readonly Subject<Unit> initializationComplete = new Subject<Unit>(); |
| 31 | + bool initialized; |
26 | 32 |
|
27 | 33 | [ImportingConstructor]
|
28 | 34 | PullRequestCreationViewModel(
|
@@ -53,7 +59,9 @@ public PullRequestCreationViewModel(IRepositoryHost repositoryHost, ISimpleRepos
|
53 | 59 |
|
54 | 60 | var branchObs = this.WhenAny(
|
55 | 61 | x => x.SourceBranch,
|
56 |
| - source => source.Value); |
| 62 | + source => source.Value) |
| 63 | + .Where(_ => initialized) |
| 64 | + .Merge(initializationComplete.Select(_ => SourceBranch)); |
57 | 65 |
|
58 | 66 | BranchValidator = ReactivePropertyValidator.ForObservable(branchObs)
|
59 | 67 | .IfTrue(x => x == null, Resources.PullRequestSourceBranchDoesNotExist)
|
@@ -86,12 +94,18 @@ public PullRequestCreationViewModel(IRepositoryHost repositoryHost, ISimpleRepos
|
86 | 94 |
|
87 | 95 | public override void Initialize([AllowNull] ViewWithData data)
|
88 | 96 | {
|
| 97 | + initialized = false; |
89 | 98 | base.Initialize(data);
|
90 | 99 |
|
91 | 100 | repositoryHost.ModelService.GetBranches(activeRepo)
|
92 | 101 | .ToReadOnlyList()
|
93 | 102 | .ObserveOn(RxApp.MainThreadScheduler)
|
94 |
| - .Subscribe(x => Branches = x); |
| 103 | + .Subscribe(x => |
| 104 | + { |
| 105 | + Branches = x; |
| 106 | + initialized = true; |
| 107 | + initializationComplete.OnNext(Unit.Default); |
| 108 | + }); |
95 | 109 | }
|
96 | 110 |
|
97 | 111 | IBranch sourceBranch;
|
|
0 commit comments