Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Effect to Watcher API #58

Merged
merged 1 commit into from
Feb 13, 2024
Merged

Switch from Effect to Watcher API #58

merged 1 commit into from
Feb 13, 2024

Conversation

littledan
Copy link
Member

No description provided.

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.
@EisenbergEffect
Copy link
Collaborator

I wasn't there for the discussions on this change, but reading through the updates, it looks good to me. In my own experimentation with the previous version of the API, I did get into situations where having an explicit watcher rather than an effect would have been better. I also think this will be more easily integrateable into some of the previous systems I've worked on, such as FAST.

@littledan littledan merged commit 88f3c60 into main Feb 13, 2024
2 checks passed
@littledan littledan deleted the watcher branch February 13, 2024 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants