-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Change design of Observer to allow pooling listeners #310
Comments
I'm going to hijack this issue with a radical idea; what if we got rid of Things have changed a lot since 0.1 when this API surface was first introduced. Now that we have scopes, we've externalised all destruction tracking, so we can append code into the current scope to handle disconnecting the listener. Beyond that, what purpose does So my proposition is this; drop the API entirely, and replace Under the hood, Fusion can now internally manage whatever reactive graph mechanisms it needs in order to dispatch those listeners. Fusion can count the number of listeners so that it destroys whatever internal objects its using once all listeners are disconnected. From there, |
This change was mostly inspired by this issue, dphfox/Fusion#310 I totally agree with Observers being *completely* redundant, and for the most part unneeded, because most the time when you're creating an Observer it's just to pipe it straight into a `:onBind()` or `:onChange()` call. I've replaced Observers with a function simply called `observe()` which takes the target and the callback as arguments and returns a disconnect function. It adds a set inside the target that holds all of the callbacks and when that target value is evaluate it calls all of those observe tasks, essentially removing the Observer "middleman". (I know I'm not good at describing these things, you can just look at the changes yourself to see what I mean)
Instead of creating a new
Observer
every time, there should be some form of sharing whenever possible. If twoObservers
are watching the same state, it should really just be oneObserver
with two listener callbacks.The text was updated successfully, but these errors were encountered: