Skip to content

Commit

Permalink
Switch from Effect to Watcher API
Browse files Browse the repository at this point in the history
remove the Effect class
Add a watcher class with:
constructor: takes options which include the notify callback (and nothing else?). Notify takes no parameters.
It is initially in “not watching” mode, and will not notify until put in “watching” mode. Notify is called when one of the signals in the watcher becomes dirty or checked, and when notify is called, the watcher is put into “not watching” mode until the next .watch() call is made.
.watch(…signals) adds signals to the watching list and sets the watcher back in “watching” mode. You can call it with no parameters after processing the notify is done, just to reactivate it
.getPending() returns an array of the signals which are in the watcher and currently in a pending or dirty state. If it were possible to call this during notify, it would always be nonempty, but notify is only allowed to queue a call to this function.
.unwatch() removes a signal (or several) from the watcher
.contents() introspects over the set of signals which have been watched
[Symbol.dispose] is a shortcut for watcher.unwatch(…watcher.contents())
The separation of notify vs getPending ends up implementing what Michel asked for earlier, of a way of querying whether an effect is dirty
There is no replacement for the effect cleanup option, as that can be easily implemented on top (it was always just a convenience feature)
So the batching is done by not calling notify again until the next watch call. At the same time, notify is called really soon, just like with effects today.
  • Loading branch information
littledan authored Feb 12, 2024
1 parent 30639ce commit 5779df5
Showing 1 changed file with 133 additions and 157 deletions.
Loading

0 comments on commit 5779df5

Please sign in to comment.