Skip to content

Commit

Permalink
chore: cleanup flat source
Browse files Browse the repository at this point in the history
  • Loading branch information
giard-alexandre committed Oct 3, 2024
1 parent e004384 commit 5d10862
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/DynamicTreeDataGrid/DynamicFlatTreeDataGridSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Reactive.Disposables;
using System.Reactive.Subjects;

using Avalonia.Controls;
Expand All @@ -12,14 +13,15 @@
namespace DynamicTreeDataGrid;

public class DynamicFlatTreeDataGridSource<TModel, TModelKey> : FlatTreeDataGridSource<TModel>,
IDynamicTreeDataGridSource<TModel>
IDynamicTreeDataGridSource<TModel>, IDisposable
where TModel : class where TModelKey : notnull {
// By default, the filtering function just includes all rows.
private readonly ISubject<Func<TModel, bool>> _filterSource = new BehaviorSubject<Func<TModel, bool>>(_ => true);
private readonly IObservable<IChangeSet<TModel, TModelKey>> _changeSet;
private readonly IObservable<IComparer<TModel>> _sort;
private readonly ISubject<IComparer<TModel>> _sortSource = new Subject<IComparer<TModel>>();
private readonly IObservable<Func<TModel, bool>> _itemsFilter;
private readonly CompositeDisposable _d = new();

public DynamicFlatTreeDataGridSource(IObservable<IChangeSet<TModel, TModelKey>> changes) : base([]) {
_itemsFilter = _filterSource;
Expand All @@ -32,18 +34,19 @@ public DynamicFlatTreeDataGridSource(IObservable<IChangeSet<TModel, TModelKey>>
var filteredChanges = _changeSet.Filter(_itemsFilter);
FilteredCount = filteredChanges.Count();

var myOperation = filteredChanges.Sort(_sort)
var disposable = filteredChanges.Sort(_sort) // Use SortAndBind?
.Bind(out var list)
.DisposeMany()
.Subscribe(set => Console.WriteLine("Changeset changed."));
.Subscribe();

_d.Add(disposable);

Items = list;

// TODO: Setup Sorted event for treeDataGridSourceImplementation?
}



public IObservable<int> FilteredCount { get; }
public IObservable<int> TotalCount { get; }

Expand Down Expand Up @@ -80,4 +83,25 @@ public bool SortBy(IColumn? column, ListSortDirection direction) {

return false;
}

#region IDisposable

private bool _disposed;

private void Dispose(bool disposing) {
if (_disposed || !disposing) {
return;
}

_d.Dispose();
_disposed = true;
}

public new void Dispose() {
Dispose(true);
base.Dispose();
GC.SuppressFinalize(this);
}

#endregion
}

0 comments on commit 5d10862

Please sign in to comment.