diff --git a/src/NexusMods.App.UI/Pages/LoadoutPage/FakeParentLoadoutItemModel.cs b/src/NexusMods.App.UI/Pages/LoadoutPage/FakeParentLoadoutItemModel.cs index 41cad3e01f..c3f01e5d16 100644 --- a/src/NexusMods.App.UI/Pages/LoadoutPage/FakeParentLoadoutItemModel.cs +++ b/src/NexusMods.App.UI/Pages/LoadoutPage/FakeParentLoadoutItemModel.cs @@ -11,24 +11,22 @@ public class FakeParentLoadoutItemModel : LoadoutItemModel { public required IObservable InstalledAtObservable { get; init; } - public required IObservable> LoadoutItemIdsObservable { get; init; } + public IObservable> LoadoutItemIdsObservable { get; } public ObservableHashSet LoadoutItemIds { get; private set; } = []; public override IReadOnlyCollection GetLoadoutItemIds() => LoadoutItemIds; private readonly IDisposable _modelActivationDisposable; - private readonly SerialDisposable _loadoutItemIdsDisposable = new(); + private readonly IDisposable _loadoutItemIdsDisposable; - public FakeParentLoadoutItemModel() : base(default(LoadoutItemId)) + public FakeParentLoadoutItemModel(IObservable> loadoutItemIdsObservable) : base(default(LoadoutItemId)) { + LoadoutItemIdsObservable = loadoutItemIdsObservable; + _loadoutItemIdsDisposable = LoadoutItemIdsObservable.OnUI().SubscribeWithErrorLogging(changeSet => LoadoutItemIds.ApplyChanges(changeSet)); + _modelActivationDisposable = WhenModelActivated(this, static (model, disposables) => { model.InstalledAtObservable.OnUI().Subscribe(date => model.InstalledAt.Value = date).AddTo(disposables); - - if (model._loadoutItemIdsDisposable.Disposable is null) - { - model._loadoutItemIdsDisposable.Disposable = model.LoadoutItemIdsObservable.OnUI().SubscribeWithErrorLogging(changeSet => model.LoadoutItemIds.ApplyChanges(changeSet)); - } }); } diff --git a/src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs b/src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs index 3684c9f578..8d42d8ed6f 100644 --- a/src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs +++ b/src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs @@ -158,11 +158,10 @@ public IObservable> ObserveNestedLoadoutI return isEnabled.HasValue ? isEnabled.Value : null; }).DistinctUntilChanged(x => x is null ? -1 : x.Value ? 1 : 0); - LoadoutItemModel model = new FakeParentLoadoutItemModel + LoadoutItemModel model = new FakeParentLoadoutItemModel(loadoutItemIdsObservable) { NameObservable = Observable.Return(libraryFile.AsLibraryItem().Name), InstalledAtObservable = installedAtObservable, - LoadoutItemIdsObservable = loadoutItemIdsObservable, IsEnabledObservable = isEnabledObservable, HasChildrenObservable = Observable.Return(true), diff --git a/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs b/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs index e459e9c9bd..90c396a39a 100644 --- a/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs +++ b/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs @@ -180,11 +180,10 @@ public IObservable> ObserveNestedLoadoutI return isEnabled.HasValue ? isEnabled.Value : null; }).DistinctUntilChanged(x => x is null ? -1 : x.Value ? 1 : 0); - LoadoutItemModel model = new FakeParentLoadoutItemModel + LoadoutItemModel model = new FakeParentLoadoutItemModel(loadoutItemIdsObservable) { NameObservable = Observable.Return(modPage.Name), InstalledAtObservable = installedAtObservable, - LoadoutItemIdsObservable = loadoutItemIdsObservable, IsEnabledObservable = isEnabledObservable, HasChildrenObservable = hasChildrenObservable,