Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi all,
In this PR, I'm proposing a new utility API to convert observables to read-only atoms. This is a part of a bigger track to improve
reactiveList
and dynamic trees in general (will elaborate more in next PR(s)).For the context of this PR, the motivation is to provide a way to temporarily convert an existing observable into a read-only atom, mainly to leverage the
.get()
API and 'distinct value' semantics in conjunction with.view(...)
to gain performance benefits.The initial proposal for the API is as follows:
One of the intended use cases for this is applying observable operators to an atom, and then being able to convert back from an observable.
Things to discuss:
Observable
as the return value to make it easier to use within existing Focal environment (e.g. as a child of anF
element). It's a bit clunky as this observable can only emit a single item.Promise
, on the other hand, wouldn't work here as we need explicit lifecycle control via subscribe/unsubscribe. We could also do something likePromise<{ atom: ...; dispose(): void }>
. It would be almost the same thing, and while trivially converted to an observable to embed into anF
element, it would be less ergonomic.complete
, or should it be left hanging indefinitely? Probably more of an implementation detail but maybe I'm wrong.fromObservable
vstoAtom
? Put it in theAtom
namespace or as an exported free function?Let me know what you think.