ReactiveUI DynamicData: WhenAnyValue, Mult. Filters, Autorefresh, Paging a collection

66 views Asked by At

I cannot find an answer on how to handle a live collection with multiple filters.

The requirement to is to make use of WhenAnyValue(mulitple filters) & AutoRefresh(x=>x.colproperty), bind Filter etc, convert, and Do some final stuff.. (manual pagination instead of virtualization in this example)

this.WhenAnyValue(x => x.Creations, x => x.PerPage, x => x.CurrentPage, x => x.IncludePublished, x => x.Search, x => x.ShowForReview)

          .Select(x => x.Item1.ToObservableChangeSet().AutoRefresh(x => x.Listing).ToCollection().Select(x => x
          .Where(x => wherefilters)
          .Reverse()
          .Skip(PerPage * (CurrentPage - 1))
          .Take(PerPage)

          .Select(x => new CreationViewModel(x)))
          .Do(x =>
          {
              if (x.Count() == 1)
                  SelectedCreation = x.First();
          })
          .Do(x =>
          FilteredCreations = x.ToObservableCollection()
              ).Subscribe()).Subscribe();

(mention: i usually do ToObservableChangeSet()...filter..transform..Bind(out readonlycollection) Should i somehow break this down ? I found ToObservableChangeSet().Filter(this.WhenAnyValue....) somehwere but it seems it isn't supported (anymore). I cannot find an example on how to handle such cases. This calls though new CreationViewModel way too many times, as I guess this being triggered is multiplied by whenanyvalues and autorefresh..

Tried to find resources for such cases, tried to break things down.

EDIT

Ok, i split up the observables, added AutoRefreshOnObservable which I missed before.

I have two main problems with this:

(1) https://github.com/LTa2022/RUIDDMyExamples/blob/master/RUIDDMyExamples/PageExtensions.cs

How to properly calculate the maximum page, my approach using toCollection is working but subscribing too many times (tried take(1) to unsubscribe immediately but that doesnt work at all) I think it makes sense from this .PageEx() extension, updating the Paging class object's MaxPage.

(2) https://github.com/LTa2022/RUIDDMyExamples/blob/master/RUIDDMyExamples/SampleListViewModel.cs

I have implemented a viewmodelfactory which delivers the right outcome by using a cache of viewmodels, but I think my obervable chain is wrong and is getting to the transform part redundatly too many times. (line 86) (or maybe it's how it works)

0

There are 0 answers