dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.19k stars 9.93k forks source link

Wrap requestAnimationFrame as OnRender interface #5502

Closed Thaina closed 5 years ago

Thaina commented 6 years ago

I would like to propose interface or virtual function that wrap around requestAnimationFrame function

Because requestAnimationFrame should be called only once at a time and triggered only when any data was changed. So it would be great if the framework would wrap and manage this function instead of us using it directly

It could be that we would have interface contain void OnRender(). And whenever the data was changed it would trigger the requestAnimationFrame to call all OnRender in the list

If possible, I think every component should run on this render callback instead of the main thread

SteveSandersonMS commented 6 years ago

I’m afraid I don’t really follow what you’re asking for. Running code on a requestAnimationFrame callback would still be on the main UI thread.

Are you able to specify more precisely what you’re looking for? Note that we’ve already designed rendering to work in the way that we think is most useful, so realistically would only change it if given very specific justifications.

Thaina commented 6 years ago

@SteveSandersonMS Surely it would be the same thread but it would like subthread that not always called unnecessary, only when the browser need to repaint, that's what requestAnimationFrame used for

Suppose we have a loop timer that changing whole table. It could be triggered faster than the browser's repaint. This leads to unnecessary command trying to change the DOM of that table more than it really be painted. With requestAnimationFrame we could separate timer updating data to run from the logic to generate table only when it really repaint

requestAnimationFrame was recommended to be used from canvas to css, everything relate to graphic in browser. So I think framework like blazor should utilize it

I think your rendering system would be the same with running on the main thread directly or under requestAnimationFrame, it just requestAnimationFrame is better be used for everything related to rendering

attilah commented 6 years ago

requestAnimationFrame is the pattern to queue deferred actions when you are doing animation. By having this supported, I think animations would not need (that much) JS interop.

It would be nice to see some Blazor animation experiment to see what does Blazor need to support fluent animation or components/elements.

rynowak commented 5 years ago

This is not something we're planning to change in this release.