34 lines
1012 B
C#
34 lines
1012 B
C#
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Reactive.Linq;
|
|
using System.Reactive.Subjects;
|
|
using DynamicData;
|
|
|
|
namespace ModpackUpdater.Apps.Manager.Ui.Models;
|
|
|
|
public class DynamicDataView<T> : INotifyPropertyChanged where T : notnull
|
|
{
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
private string? searchText;
|
|
private readonly Subject<string?> searchTextSubject = new();
|
|
|
|
public SourceList<T> List { get; } = new();
|
|
public ReadOnlyObservableCollection<T> View { get; }
|
|
|
|
public DynamicDataView(Func<string?, Func<T, bool>> predicate)
|
|
{
|
|
List.Connect()
|
|
.Filter(searchTextSubject/*.Throttle(TimeSpan.FromMilliseconds(250))*/.Select(predicate))
|
|
.Bind(out var view)
|
|
.Subscribe();
|
|
searchTextSubject?.OnNext(searchText);
|
|
View = view;
|
|
}
|
|
|
|
public string? SearchText
|
|
{
|
|
get => searchText;
|
|
set => searchTextSubject.OnNext(searchText = value);
|
|
}
|
|
} |