Skip to content

Commit

Permalink
Merge pull request #2079 from Nexus-Mods/fix/treemodel-missed-activation
Browse files Browse the repository at this point in the history
Fix data not being initialized for some rows in LoadoutView when fast scrolling through
  • Loading branch information
Al12rs authored Sep 24, 2024
2 parents 7a1fbfc + 84f6f57 commit 5ecef6a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ public class FakeParentLoadoutItemModel : LoadoutItemModel
{
public required IObservable<DateTime> InstalledAtObservable { get; init; }

public required IObservable<IChangeSet<LoadoutItemId, EntityId>> LoadoutItemIdsObservable { get; init; }
public IObservable<IChangeSet<LoadoutItemId, EntityId>> LoadoutItemIdsObservable { get; }
public ObservableHashSet<LoadoutItemId> LoadoutItemIds { get; private set; } = [];

public override IReadOnlyCollection<LoadoutItemId> GetLoadoutItemIds() => LoadoutItemIds;

private readonly IDisposable _modelActivationDisposable;
private readonly SerialDisposable _loadoutItemIdsDisposable = new();
private readonly IDisposable _loadoutItemIdsDisposable;

public FakeParentLoadoutItemModel() : base(default(LoadoutItemId))
public FakeParentLoadoutItemModel(IObservable<IChangeSet<LoadoutItemId, EntityId>> 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));
}
});
}

Expand Down
3 changes: 1 addition & 2 deletions src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ public IObservable<IChangeSet<LoadoutItemModel, EntityId>> 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),
Expand Down
3 changes: 1 addition & 2 deletions src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,10 @@ public IObservable<IChangeSet<LoadoutItemModel, EntityId>> 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,
Expand Down

0 comments on commit 5ecef6a

Please sign in to comment.