Skip to content

Commit

Permalink
Merge pull request #45 from DamianReeves/master
Browse files Browse the repository at this point in the history
Fix for issue #44
  • Loading branch information
Paul Betts committed Jan 30, 2012
2 parents c9499dc + 670e02e commit 0cc9d01
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
20 changes: 20 additions & 0 deletions ReactiveUI.Tests/ObservableCollectionViewTests.cs
Expand Up @@ -154,6 +154,26 @@ public void Sort_when_item_property_changes_in_reactive_collection()
subject.Select(x => x.Name).AssertAreEqual(new[] { "d", "b", "c", "z" });
}

[Fact]
public void Remove_when_item_property_changes_donot_meet_filter_criteria_in_reactive_collection() {
var source = new ReactiveCollection<Mock>(
new List<Mock>
{
new Mock{Name = "b"},
new Mock{Name = "a", Enabled = true},
new Mock{Name = "c", Enabled = true}
}) {
ChangeTrackingEnabled = true
};
var subject = new ObservableCollectionView<Mock>(
source,
x => x.Enabled,
null);

source.ForEach(x => x.Enabled = false);
subject.Select(x => x.Name).AssertAreEqual(new string[]{});
}

public class Mock : ReactiveObject
{
string _Name;
Expand Down
11 changes: 8 additions & 3 deletions ReactiveUI/ObservableCollectionView.cs
Expand Up @@ -78,10 +78,15 @@ void wireNotificationHandlers()

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

public IObservable<int> ViewCountChanged
Expand Down

0 comments on commit 0cc9d01

Please sign in to comment.