raimohanska / harmaja

Experimental frontend framework
Other
84 stars 5 forks source link

Issue with scoping observables #46

Open raimohanska opened 3 years ago

raimohanska commented 3 years ago

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, including combine actually call get() when created, so they fail immediately.

I see these options:

A) Replace componentScope with untilUnmount 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't get a value of these observables in the constructor, but of course to do that you could implement the untilUnmount scope as an alternative and then you'd have to deal with the leak possibility.

raimohanska commented 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.

raimohanska commented 3 years ago

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!

raimohanska commented 3 years ago

What's left to do: documentation for this gotcha!