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

Add short descriptions for scan, catch, and switchMap #142

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,33 @@ If the subscriber has already been aborted (i.e., `subscriber.signal.aborted` is

We propose the following operators in addition to the `Observable` interface:

- `switchMap(mapFn)`
- Maps the value to a new observable, then subscribes to it, flattening its values
into the output. When another value arrives from source, the previously mapped
observable's subscription is aborted, and the new value is mapped to a value that is
converted to an observable with `from` internally, and subscribed to, flattening its values
into the output. This operator is useful for switching between streams, toggling streams
on and off, and implicitly interupting async work and starting new work.
- `takeUntil(Observable)`
- Returns an observable that mirrors the one that this method is called on,
until the input observable emits its first value
- `catch()`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems redundant with the other PR, right?

- Like `Promise.catch()`, it takes a mapping function which is fired if the observable
source emits an error. The mapping function should map into a new value which will be converted
into an observable with `from` internally and subscribed to in lieu of the errored source.
- Returns an `Observable` that mirrors the source observable exactly, other than when the
source observable errors.
- `finally()`
- Like `Promise.finally()`, it takes a callback which gets fired after the
observable completes in any way (`complete()`/`error()`).
- Returns an `Observable` that mirrors the source observable exactly. The callback
passed to `finally` is fired when a subscription to the resulting observable is terminated
for _any reason_. Either immediately after the source completes or errors, or when the consumer
unsubscribes by aborting the subscription.
- `scan(reducer, initValue?)`
- Like `reduce()`, only it emits the accumulated value synchronously after each call to
the reducer. `observable.reduce(fn, init)` is the same as `observable.scan(fn, init).last()`
- This is a common tool used in localized state tracking, and can be used to create a "redux pattern".

Versions of the above are often present in userland implementations of
observables as they are useful for observable-specific reasons, but in addition
Expand Down
Loading