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

Atom.fromObservable #51

Merged
merged 15 commits into from
Nov 6, 2019
Merged

Atom.fromObservable #51

merged 15 commits into from
Nov 6, 2019

Conversation

blacktaxi
Copy link
Member

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:

function fromObservable<T>(src: Observable<T>): Observable<ReadOnlyAtom<T>>

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:

  • I'm using Observable as the return value to make it easier to use within existing Focal environment (e.g. as a child of an F 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 like Promise<{ atom: ...; dispose(): void }>. It would be almost the same thing, and while trivially converted to an observable to embed into an F element, it would be less ergonomic.
  • Should the returned observable immediately complete, or should it be left hanging indefinitely? Probably more of an implementation detail but maybe I'm wrong.
  • Naming and location. fromObservable vs toAtom? Put it in the Atom namespace or as an exported free function?

Let me know what you think.

@blacktaxi blacktaxi changed the title WIP: Atom.fromObservable Atom.fromObservable Oct 30, 2019
@blacktaxi blacktaxi merged commit 0640076 into master Nov 6, 2019
@blacktaxi blacktaxi deleted the f-observable-to-atom branch November 6, 2019 19:30
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

Successfully merging this pull request may close these issues.

1 participant