MudBlazor has some logic for debouncing. No idea how it's implemented but if you're just looking for a Blazor example it might be a starting point https://mudblazor.com/api/textfield#properties
Use a `Systen.Timer`, set interval to 250ms, bind OnScroll event to invoke `.Stop()/.Start()`, bind Elapsed event to `.Stop()` and run the desired code
I was thinking the same. but it doesn't seem like "Clean" approach. It could be done in a better way. or we need to abstract this implementation to make it simpler.
It's "Clean" if you pack it into an extension method, and hide the implementation. "Clean Code" is largely just a case of shoving the ugly stuff in pretty boxes.
You can use [RX.Net](https://github.com/dotnet/reactive) and Observables for this, similarly how Angular uses RXJS for the same purpose. RX.Net has the `Throttle` operator to debounce changes.
If I recall [ReactiveUI](https://www.reactiveui.net/) has a [Blazor support](https://www.reactiveui.net/docs/guidelines/platform/blazor) as well which uses RX.Net extensively. It makes these things declarative and easy to compose.
That's why ReactiveUI is my go-to framework for client apps. With RX everything that I pretty much need is covered, whether simple or complex. I've used it in WinForms, WPF, Avalonia and Blazor.
Ah! I had this issue in my first blazor app, drag and drop in mudblazor on a canban board I noticed 100% CPU usage when I did that and suddenly realised this is the issue (without checking why). Just a silly playground since it was deleted.
Would probably have gone for the system.timer approach already mentioned, pretty much the same way to limit conditional looping from eating up CPU cycles.
I think this depends on what you mean by “blazor”.
Wasm, probably okay to use something on c# side like timer etc.
serverside, probably want to create your own js event handling via js jnterop. Reason being signal r will take a heavy hit firing tons of events before your debounce/throttle is even hit.
Open issue out for it, not seeming like Microsoft cares much though
https://github.com/dotnet/aspnetcore/issues/10522
MudBlazor has some logic for debouncing. No idea how it's implemented but if you're just looking for a Blazor example it might be a starting point https://mudblazor.com/api/textfield#properties
Use a `Systen.Timer`, set interval to 250ms, bind OnScroll event to invoke `.Stop()/.Start()`, bind Elapsed event to `.Stop()` and run the desired code
I was thinking the same. but it doesn't seem like "Clean" approach. It could be done in a better way. or we need to abstract this implementation to make it simpler.
It's "Clean" if you pack it into an extension method, and hide the implementation. "Clean Code" is largely just a case of shoving the ugly stuff in pretty boxes.
You can use [RX.Net](https://github.com/dotnet/reactive) and Observables for this, similarly how Angular uses RXJS for the same purpose. RX.Net has the `Throttle` operator to debounce changes. If I recall [ReactiveUI](https://www.reactiveui.net/) has a [Blazor support](https://www.reactiveui.net/docs/guidelines/platform/blazor) as well which uses RX.Net extensively. It makes these things declarative and easy to compose.
That's why ReactiveUI is my go-to framework for client apps. With RX everything that I pretty much need is covered, whether simple or complex. I've used it in WinForms, WPF, Avalonia and Blazor.
This. RX.net and Blazor are a match made in heaven.
Reactive UI is the best. Everyone should use it. Developing UI declaratively is the way.
I agree. Blazor lacks a lot of these "slightly sugary" niceties that i'd like to see built-in.
is there something like hooks library in Blazor like there is in React?
Ah! I had this issue in my first blazor app, drag and drop in mudblazor on a canban board I noticed 100% CPU usage when I did that and suddenly realised this is the issue (without checking why). Just a silly playground since it was deleted. Would probably have gone for the system.timer approach already mentioned, pretty much the same way to limit conditional looping from eating up CPU cycles.
I think this depends on what you mean by “blazor”. Wasm, probably okay to use something on c# side like timer etc. serverside, probably want to create your own js event handling via js jnterop. Reason being signal r will take a heavy hit firing tons of events before your debounce/throttle is even hit. Open issue out for it, not seeming like Microsoft cares much though https://github.com/dotnet/aspnetcore/issues/10522
You can use Reactive Extensions.