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

Callback when a model goes out of use. #59

Open
back2dos opened this issue May 11, 2020 · 5 comments
Open

Callback when a model goes out of use. #59

back2dos opened this issue May 11, 2020 · 5 comments

Comments

@back2dos
Copy link
Member

It should be possible to detect when none of a model's observable/editable properties are in use and so that any underlying subscriptions (to a websocket or something) can be cleaned up.

@kevinresol
Copy link
Member

Will it be like "Suspendable" i.e. can be deactivated/reactivated repeatedly?

@kevinresol
Copy link
Member

In react hook there is useEffect, I wonder if it make sense to have something like this?

@:effect function subscribe():CallbackLink;

this would track observables used in the function and re-call when necessary.

@back2dos
Copy link
Member Author

back2dos commented Aug 5, 2020

Not sure I follow 100%. Can you please elaborate on how this would be used?

@kevinresol
Copy link
Member

kevinresol commented Aug 6, 2020

Roughly something like this:

@:observable var id:String;
@:editable var currentValue:Int;
@:effect function subscribe():CallbackLink {
    // when `id` changes, this function will be called again, the last CallbackLink produced will be dissolved at the same time
    return subscribeForExternalChange(id, value -> currentValue = value);
}

@:effect is a function that will produce side effects, and returns a callback link to undo it, and when the model goes out of use, the callback link will be called to cleanup resources. maybe it is just equivalent to untilUnmounted in a view

@kevinresol
Copy link
Member

I am interested in implementing this, are there any tips where I should get started?

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

No branches or pull requests

2 participants