DynamicData icon indicating copy to clipboard operation
DynamicData copied to clipboard

[Bug]: Filter is preventing empty change notifications despite "suppressEmptyChangeSets: false" on Connect

Open MagneticLlama opened this issue 3 years ago • 3 comments

Describe the bug 🐞

Subscribe callback will not be called if Filter removes all entries from a source cache on its initial load despite "suppressEmptyChangeSets: false" being set on Connect.

Step to reproduce

var sourceCache = new SourceCache<Item, int>(p => p.Id);
sourceCache.Connect(suppressEmptyChangeSets: false)
    .Filter(x => false)
    .Bind(out items)
    .Subscribe(x =>
    {
        Console.WriteLine($"Got {items.Count} results");
    });

Expected behavior

Subscribe's onNext and onCompleted should trigger even if the Filter results in no entries when suppressEmptyChangeSets is set to false on Connect.

DynamicData Version

7.9.4

MagneticLlama avatar Jun 30 '22 15:06 MagneticLlama

Unfortunately the limitation of suppressEmptyChangeSets is that it can only suppress the empty notifications for the connect method and subsequent operators.

The alternative is to apply the NotEmpty operator after Filter.

var sourceCache = new SourceCache<Item, int>(p => p.Id);
sourceCache.Connect(suppressEmptyChangeSets: false)
    .Filter(x => false)
     .NotEmpty()
    .Bind(out items)
    .Subscribe(x =>
    {
        Console.WriteLine($"Got {items.Count} results");
    });

RolandPheasant avatar Jul 11 '22 08:07 RolandPheasant

I tried to do what you suggested, and if I'm understanding it correctly, that's the opposite of what I need. I don't want to suppress the empty notification. If my initial load is empty, I expected Subscribe to be hit because suppressEmptyChangeSets is set to false on Connect. Using Filter, even if it's not filtering out any entries, is preventing this.

I thought it might be related to this issue https://github.com/reactivemarbles/DynamicData/issues/581

MagneticLlama avatar Jul 11 '22 13:07 MagneticLlama

Doh, I misread and now see what you mean.

I have to say I wish I never ever supressed notifications in the first change and instead allowed consumers to take control to filtering out empty changes. The reason I will not completely remove this feature is in many existing systems, performance and behaviour would be badly affected.

In this case as it's a static filter I am sure it will be straight forward to allow the first time notification through even when empty. However it will probably need careful consideration before jumping in and changing it,

RolandPheasant avatar Jul 11 '22 13:07 RolandPheasant

@MagneticLlama .Filter() has its own suppressEmptyChangeSets parameter that can be used to resolve this issue.

JakenVeina avatar Nov 18 '23 08:11 JakenVeina

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 18 '23 01:12 github-actions[bot]