From d60d6a65a6972b9778398ac8a2ac18e6356cb384 Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Sun, 13 Oct 2019 03:03:41 -0500 Subject: [PATCH] Removed unnecessary command subject The bug was that the way commands were defined, a new instance was made every property access. Swapped to readonly gets so it's a single instance. --- Wabbajack/AppState.cs | 23 +++++++++++++---------- Wabbajack/Extensions/ReactiveUIExt.cs | 8 ++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Wabbajack/AppState.cs b/Wabbajack/AppState.cs index 85e2d20e..dd0f5455 100644 --- a/Wabbajack/AppState.cs +++ b/Wabbajack/AppState.cs @@ -74,17 +74,14 @@ namespace Wabbajack public bool Installing { get => _Installing; set => this.RaiseAndSetIfChanged(ref _Installing, value); } // Command properties - public IReactiveCommand ChangePathCommand => ReactiveCommand.Create(ExecuteChangePath); - public IReactiveCommand ChangeDownloadPathCommand => ReactiveCommand.Create(ExecuteChangeDownloadPath); + public IReactiveCommand ChangePathCommand { get; } + public IReactiveCommand ChangeDownloadPathCommand { get; } public IReactiveCommand BeginCommand { get; } - public IReactiveCommand ShowReportCommand => ReactiveCommand.Create(ShowReport); - public IReactiveCommand VisitNexusSiteCommand => ReactiveCommand.Create(VisitNexusSite); + public IReactiveCommand ShowReportCommand { get; } + public IReactiveCommand VisitNexusSiteCommand { get; } public IReactiveCommand OpenReadmeCommand { get; } - public IReactiveCommand OpenModListPropertiesCommand => ReactiveCommand.Create(OpenModListProperties); - // ToDo - // This subject is not desirable. Need to research why command's IsExecuting observable not firing, as we'd prefer to hook onto that instead - private Subject _slideshowCommandTriggeredSubject = new Subject(); - public ReactiveCommand SlideShowNextItemCommand => ReactiveCommand.Create(() => _slideshowCommandTriggeredSubject.OnNext(Unit.Default)); + public IReactiveCommand OpenModListPropertiesCommand { get; } + public IReactiveCommand SlideShowNextItemCommand { get; } = ReactiveCommand.Create(() => { }); public AppState(TaskMode mode) { @@ -101,6 +98,12 @@ namespace Wabbajack Mode = mode; + // Define commands + this.ChangePathCommand = ReactiveCommand.Create(ExecuteChangePath); + this.ChangeDownloadPathCommand = ReactiveCommand.Create(ExecuteChangeDownloadPath); + this.ShowReportCommand = ReactiveCommand.Create(ShowReport); + this.VisitNexusSiteCommand = ReactiveCommand.Create(VisitNexusSite); + this.OpenModListPropertiesCommand = ReactiveCommand.Create(OpenModListProperties); this.OpenReadmeCommand = ReactiveCommand.Create( execute: this.OpenReadmeWindow, canExecute: this.WhenAny(x => x.ModList) @@ -179,7 +182,7 @@ namespace Wabbajack // If the natural timer fires Observable.Interval(TimeSpan.FromSeconds(10)).Unit(), // If user requests one manually - _slideshowCommandTriggeredSubject) + this.SlideShowNextItemCommand.StartingExecution()) // When enabled, fire an initial signal .StartWith(Unit.Default) // Only subscribe to slideshow triggers if enabled and installing diff --git a/Wabbajack/Extensions/ReactiveUIExt.cs b/Wabbajack/Extensions/ReactiveUIExt.cs index a86a9827..0f1bda7a 100644 --- a/Wabbajack/Extensions/ReactiveUIExt.cs +++ b/Wabbajack/Extensions/ReactiveUIExt.cs @@ -84,6 +84,14 @@ namespace Wabbajack .Switch(); } + public static IObservable StartingExecution(this IReactiveCommand cmd) + { + return cmd.IsExecuting + .DistinctUntilChanged() + .Where(x => x) + .Unit(); + } + /// These snippets were provided by RolandPheasant (author of DynamicData) /// They'll be going into the official library at some point, but are here for now. #region Dynamic Data EnsureUniqueChanges