-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
Feature: TransformOnObservable Operator for SourceCache #841
Feature: TransformOnObservable Operator for SourceCache #841
Conversation
src/DynamicData.Tests/API/ApiApprovalTests.DynamicDataTests.DotNet8_0.verified.txt
Show resolved
Hide resolved
// Helper to emit any pending changes when all the updates have been handled | ||
void EmitChanges() | ||
{ | ||
if (Interlocked.Decrement(ref updateCounter) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the concept of an update counter to batch results is inspired. The same concept would probably benefit several other operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the concept of an update counter to batch results is inspired. The same concept would probably benefit several other operations.
Thank you! 😊
I used it for TransformManyAsync
to get behavior similar to TransformMany
after you stressed the importance of minimizing the number of ChangeSets. I was also thinking that it might be beneficial to use in other places, so I'll keep a lookout for those.
There is some nuance to using it. For example, you have to increment the counter before the Synchronize
so that updates coming in on other threads are counted and the emission downstream is deferred until it can be handled.
There are also some downsides:
- More difficult (sometimes impossible) to deterministically know how many changesets you'll get
- Possible to never get a downstream changeset (if updates happen constantly)
Doh, I've approved but I just noticed a test is failing,. |
Yeah, I changed something to use |
- Overloads that take an Action that uses the Key - Now use common implementation - OnItemRemoved doesn't use special operator unless necessary
Update to use new OnItemRemoved operator that gives the key to the callback
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
As requested by #672, this creates a new operator
TransformOnObservable
that will transform each item in a Cache ChangeSet into an Observable and use the latest value from that Observable as the value the corresponding key in the resulting change set.Uses an update counter to minimize the number of changesets emitted downstream. If the source emits a changeset with 5 add events, and each of the sub-observables emits a value upon subscription, then the downstream should see a single changeset with 5 add events.
Notes
Update
changes for the same Key value.Bonus Changes
OnItem*
operators:OnItemRemoved
to not use the special class unless the "invokeOnUnsub" flag is set because it uses an extra Cache and lock that isn't needed