Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Last active February 9, 2021 17:00
Show Gist options
  • Save rdelrosario/4498853136e5d3de2e58866a40c61430 to your computer and use it in GitHub Desktop.
Save rdelrosario/4498853136e5d3de2e58866a40c61430 to your computer and use it in GitHub Desktop.
public class ObservableGroupedCollection<TGroupKey, TObject, TKey> : ObservableCollectionExtended<TObject>, IDisposable
{
public TGroupKey Key { get; }
public ObservableGroupedCollection(IGroup<TObject, TKey, TGroupKey> group, IObservable<Func<TObject, bool>> filter, IObservable<IComparer<TObject>> comparer)
{
this.Key = group.Key;
//load and sort the grouped list
var dataLoader = group.Cache.Connect()
.Filter(filter)
.Sort(comparer)
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(this) //make the reset threshold large because xamarin is slow when reset is called (or at least I think it is @erlend, please enlighten me )
.Subscribe();
_cleanUp = new CompositeDisposable(dataLoader);
}
public void Dispose()
{
_cleanUp.Dispose();
}
private readonly IDisposable _cleanUp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment