Skip to content

Commit

Permalink
Merge pull request #16 from willowtreeapps/simplify-can-create-behavi…
Browse files Browse the repository at this point in the history
…or-subject

Simplify the logic to disable the "Create Request" button
  • Loading branch information
APIWT authored Sep 22, 2021
2 parents dc5baca + 1a03b8d commit 1bca848
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Client/Workbooks/ViewModels/WorkbookViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ public WorkbookViewModel(
openRequestCommand,
workbookState);

// This has to be constructed by hand rather than intuited from a lambda expression because Expression has different arity than Expression<Func<WorkbookViewModel, int>>
Expression watchChain = Expression.Property(Expression.Property(Expression.Property(Expression.Property(Expression.Parameter(typeof(WorkbookViewModel)), "WorkbookItems"), "FolderItems"), "Items"), "Count");
this.SubscribeToExpressionChain<WorkbookViewModel, int>(watchChain).Select(countProperty => countProperty.Value > 0).Subscribe(deferredCanCreateItemBehaviorSubject);
deferredCanCreateItemBehaviorSubject.OnNext(this.WorkbookItems.FolderItems.Items.Count > 0); // Reinject the current value once load completes.
this
.WhenAnyValue(viewModel => viewModel.WorkbookItems.FolderItems.Items.Count)
.Select(c => c > 0)
.Subscribe(deferredCanCreateItemBehaviorSubject);
}

/// <summary>
Expand Down

0 comments on commit 1bca848

Please sign in to comment.