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

Observable.from() & accept conversions #60

Merged
merged 5 commits into from
Sep 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,17 @@ interface Observable {

undefined finally(VoidFunction callback);

// Constructs a native Observable from `value` if it's any of the following:
// - Observable
// - Promise
// - Iterable
// - AsyncIterable
static Observable from(any value);

// Observable-returning operators. See "Operators" section below.
Observable takeUntil(Observable notifier);
// `takeUntil()` can consume promises, iterables, async iterables, and other
// observables.
Observable takeUntil(any notifier);
Observable map(Mapper mapper);
Observable filter(Predicate predicate);
Observable take(unsigned long long);
Expand Down Expand Up @@ -382,6 +391,21 @@ new event listener whose events are exposed through the Observer handler
functions and are composable with the various
[combinators](#operators) available to all Observables.

#### Constructing & converting objects to Observables

Observables can be created by their native constructor, as demonstrated above,
or by the `Observable.from()` static method. This method constructs a native
Observable from any of the following objects:

- `Observable` (in which case it just returns the given object)
domfarolino marked this conversation as resolved.
Show resolved Hide resolved
- `Promise` (or any thenable)
- `Iterable` (anything with `Symbol.iterator`)
- `AsyncIterable` (anything with `Symbol.asyncIterator`)

Furthermore, any method on the platform that wishes to accept an `Observable`
can take any of the above objects as well (by accepting a WebIDL `any`), which
will be converted to a native Observable before being subscribed to.
domfarolino marked this conversation as resolved.
Show resolved Hide resolved

#### Lazy, synchronous delivery

Crucially, Observables are "lazy" in that they do not start emitting data until
Expand Down Expand Up @@ -452,7 +476,10 @@ methods](https://tc39.es/proposal-iterator-helpers/#sec-iteratorprototype) to
- `some()`
- `every()`
- `find()`
- maybe: `from()`

And the following method statically on the `Iterator` constructor:

- `from()`

We expect userland libraries to provide more niche operators that integrate with
the `Observable` API central to this proposal, potentially shipping natively if
Expand Down