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

[Bug]: SourceCache with Sample and TransformWithInlineUpdate throws DynamicData.MissingKeyException #955

Open
ethpch opened this issue Oct 18, 2024 · 7 comments
Labels

Comments

@ethpch
Copy link

ethpch commented Oct 18, 2024

Describe the bug 🐞

SourceCache with Sample and TransformWithInlineUpdate throws DynamicData.MissingKeyException with message "1 is not found." Sample with Transform works well, but I need inline update to ensure correct selection behavior in DataGrid control.

SourceCache<..., ...> cache = new(...);
cache.Connect()
     .Sample(TimeSpan.FromMilliseconds(1000))
     //.Transform(x => ...)         //works well
     .TransformWithInlineUpdate(    //throws on running
         transformFactory: x => ...,
         updateAction: (y, x) => ...,
         )
     .Subscribe();

Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(100))
    .Subscribe(x =>
        cache.AddOrUpdate(...);
    );

And I find that if difference of elapse of Timer and Sample is small like this:

cache.Connect()
     .Sample(TimeSpan.FromMilliseconds(1000))
...
Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(980))

it won't throw the exception, sometimes, maybe first run works well but stop and re-run throws. If elapse of Timer is greater than Sample it won't throw.

I have uploaded the minimum console project.

Step to reproduce

  1. Clone the reproduction repository
  2. Build and run
  3. See error

Reproduction repository

https://github.com/ethpch/DynamicData.Test

Expected behavior

Sample with TransformWithInlineUpdate works as expected.

Screenshots 🖼️

image

IDE

Visual Studio 2022

Operating system

Windows

Version

23H2, 22631.4317

Device

Desktop

DynamicData Version

9.0.4

Additional information ℹ️

No response

@ethpch ethpch added the bug label Oct 18, 2024
@JakenVeina
Copy link
Collaborator

Props for minimum repro. I'll take a look this weekend.

@RolandPheasant
Copy link
Collaborator

Sample is not supported by Dynamic Data.

@ethpch
Copy link
Author

ethpch commented Oct 19, 2024

Thanks for your explanation.

So what is the replacement of Sample?

I have searched DynamicData operators, and now I'm using Batch instead. It looks good on UI Datagrid control, But I'm not sure how it works.

For example, the timer produce Item1, Item2, ... Item10 per 100ms, Batch dueTime is 1,000ms, then it just output the Item10 one time, or output Item1 to Item10 in order at the same time? I Tested this case and I think the last is correct, but I just need a throttle operator to choose one output object, the first(Throttle, not debounce) or the last(Sample). Refresh 10 times maybe cost a lot.

And is there a documentation for the unsupported standard rx operators? I think this will save a lot of time for newcomers.

@RolandPheasant
Copy link
Collaborator

Batch is basically a buffer which captures all changes within a specified time period and flattens the changes back out into a single change set. This is important because dynamic data relies on changes being captured in sequence, otherwise it cannot determine what is an add, an update or remove. Sample on the other hand will skip changes and therefore violates the concept of a chabgeset

@RolandPheasant
Copy link
Collaborator

I think the equivalent of sample would be like batch but to produce a unique a change set of unique changes per key within a change set. This is possible, but I am away from my laptop this weekend. I'll post a snippet early next week.

@ethpch
Copy link
Author

ethpch commented Oct 19, 2024

I think the equivalent of sample would be like batch but to produce a unique a change set of unique changes per key within a change set.

So Sample will take the last change of unique key. This is what I want. Thanks for your work!

@JakenVeina
Copy link
Collaborator

JakenVeina commented Oct 19, 2024

Native .Sample() is about taking a random sampling of values from a stream, so a DynamicData corollary would probably have to be about taking a random sampling of items from a collection. I.E. pick a few items/keys in the collection, at random, and continuously observe those. Or maybe more like, each time an Add change occurs, calculate an X% chance of forwarding it downstream, or filtering it out. You could achieve either of these reasonably with a .Filter() operator today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants