Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObservableCollectionView does not remove items which do not match the filter #44

Closed
DamianReeves opened this issue Jan 30, 2012 · 5 comments
Labels

Comments

@DamianReeves
Copy link

I've been using the ObservableCollectionView's ability to filter items in the collection but I saw issues where items which were modified in order to no longer meet the filter criteria not being removed. It seems this issue is due to how the ObserveCollectionItemChanged() call is made:

source.ObserveCollectionItemChanged<T>()
    .Where(updateFilter)
    .Select(x => x.Sender)
    .Where(filter)
    .ObserveOn(RxApp.DeferredScheduler)
    .Subscribe(updateItem);

The above will never call updateItem to remove items which don't meet the filter criteria.
This can be fixed by adding the following code as well:

source.ObserveCollectionItemChanged<T>()
    .Where(updateFilter)
    .Select(x => x.Sender)
    .Where(x=> !filter(x))
    .ObserveOn(RxApp.DeferredScheduler)
    .Subscribe(removeItem);
@anaisbetts
Copy link
Member

How about instead:

source.ObserveCollectionItemChanged<T>()
    .Where(updateFilter)
    .Select(x => new { Item = x.Sender, Match = filter(x.Sender) })
    .ObserveOn(RxApp.DeferredScheduler)
    .Subscribe(x => {
        if (x.Match) {
            updateItem(x);
        } else {
            removeItem(x);
        }
    });

@DamianReeves
Copy link
Author

I tried this in my unit tests and it works also (much nicer by the way).

source.ObserveCollectionItemChanged<T>()
    .Where(updateFilter)
    .Select(x => new { Item = x.Sender, Match = filter(x.Sender) })
    .ObserveOn(RxApp.DeferredScheduler)
    .Subscribe(x => {
        if (x.Match) {
            updateItem(x.Item);
        } else {
            removeItem(x.Item);
        }
    });

Note: the x.Item change

@anaisbetts
Copy link
Member

hwhoops. Looks good, send me a PR!

anaisbetts pushed a commit that referenced this issue Jan 30, 2012
@DamianReeves
Copy link
Author

This issues seems to have been reintroduced in the latest source code version. The code fix is gone.

@anaisbetts
Copy link
Member

ObservableCollectionView is deprecated, you want to use CreateDerivedCollection.

On Fri, Mar 23, 2012 at 7:38 PM, DamianReeves
reply@reply.github.com
wrote:

This issues seems to have been reintroduced in the latest source code version. The code fix is gone.


Reply to this email directly or view it on GitHub:
https://github.com/xpaulbettsx/ReactiveUI/issues/44#issuecomment-4671177

@lock lock bot added the outdated label Jun 26, 2019
@lock lock bot locked and limited conversation to collaborators Jun 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants