Cysharp / R3

The new future of dotnet/reactive and UniRx.
MIT License
1.72k stars 70 forks source link

Blazor Support #139

Closed michaelstonis closed 4 months ago

michaelstonis commented 4 months ago

Is Blazor Support possible?

What could a TimeProvider look like? There is no direct dispatcher and the StateHasChanged method is not very granular. I could still see there being a benefit in having something to automatically call StateHasChanged based on property updates or similar though.

neuecc commented 4 months ago

I see, Blazor also seems to have a SynchronizationContext, so it may be possible to do something.

neuecc commented 4 months ago

I've implemented SynchronizationContextTimeProvider for Blazor. StateHasChanged should be executed manually.

image

neuecc commented 4 months ago

I've introduced AddBlazorR3 for default TimeProvider as request scoped. https://github.com/Cysharp/R3?tab=readme-ov-file#blazor

michaelstonis commented 4 months ago

I've implemented SynchronizationContextTimeProvider for Blazor. StateHasChanged should be executed manually.

I think this is great! Having StateHasChanged called manually seems like a reasonable expectation since we don't have a better way to manage it and it would be better to be careful with how many updates we push there.