ds300/derivablejs

Trigger reaction cycles at custom intervals

ds300 opened this issue · 1 comments

It might be desirable to globally control when reactions occur, e.g. in a render loop with requestAnimationFrame for games and other applications which intensively update state.

The ability to do this should be trivial to expose. It can be implemented on top of the existing transaction plumbing. It would simply involve modifying the execution environment to be in a transactional state by default. In order to run reactions the global transaction is simply committed and then started again immediately.

Proposed API something like:

const ticker = Havelock.globalTick();
// global txn now set up. Returned value should be a refcounted singleton.

ticker.tick();
// any pending reactions run

ticker.release();
// tear down global txn when refcount is 0

This should be considered an advanced feature for frameworkey bits, so I think the refcount thing shouldn't be too much of an issue.

I did this ages ago - #11