natefaubion / purescript-spork

Elm-like for PureScript
MIT License
157 stars 9 forks source link

What is the idea behind `Scheduler` and its `MutationObserver` usage? #32

Closed paluh closed 4 years ago

paluh commented 4 years ago

Once again thanks for creating Spork!

I want to use Spork fork (without vdom) as a state machine for canvas rendering and even for some "self contained" state machines not related directly to the DOM. It seems really easy to drop vdom from Spork and replace it with custom renderer but the last thing which I want to understand and is tight directly to the DOM is a Schduler module which uses MutationObserver.

Could you please explain briefly what is the idea behind it and how it works?

natefaubion commented 4 years ago

MutationObservers run as part of the browser micro task queue, which is drained at the end of the current event loop tick. It’s similar to using requestAnimationFrame, but more prompt. It lets you batch renders in the case of multiple events firing due to bubbling. It’s unlikely that you need it for canvas.

paluh commented 4 years ago

Thanks!

paluh commented 4 years ago

P.S. Of course it was not necessary to fork spork. I'm using it as a library importing core primitives. I'm only providing my own App type and related functions / types.