Open raimohanska opened 3 years ago
The leak caused by option A would be minor in the sense that it would keep observables alive but not cause any side effects on the components that are not mounted yet. Anyway I don't find this acceptable behavior.
Made some progress with option B. The goal is that all Lonna properties can be subscribed to before scope start and this should be the situation at the moment. EDIT: this is also the current situation, so I think we're there!
What's left to do: documentation for this gotcha!
Currently
componentScope()
can be used to limit the lifetime of a Lonna observable to the component's lifetime.This is problematic because the lifetime starts on component mount, so it's not yet scope when running the component constructore. Due to this, you cannot
get()
the value of scoped observable. Additionally some observables, includingcombine
actually callget()
when created, so they fail immediately.I see these options:
A) Replace
componentScope
withuntilUnmount
so that scope will start in the constructor already. Here the problem lies in that if a component is never mounted, it will cause a leak B) Make sure that all Lonna observables can be subscribed to also before scope start and that listeners added before scope start will be notified on scope start. Still, you couldn'tget
a value of these observables in the constructor, but of course to do that you could implement theuntilUnmount
scope as an alternative and then you'd have to deal with the leak possibility.