Open back2dos opened 4 years ago
Will it be like "Suspendable" i.e. can be deactivated/reactivated repeatedly?
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.
Not sure I follow 100%. Can you please elaborate on how this would be used?
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
I am interested in implementing this, are there any tips where I should get started?
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.