Skip to content

Instantly share code, notes, and snippets.

@jxc876
Last active April 1, 2019 15:27
Show Gist options
  • Save jxc876/fa75eefac584c2b2bd1b1e579e65c3d4 to your computer and use it in GitHub Desktop.
Save jxc876/fa75eefac584c2b2bd1b1e579e65c3d4 to your computer and use it in GitHub Desktop.
Gist

Combination

  • combineAll
  • combineLatest
  • concat - Subscribe to Observables in order as previous completes, emit values. (The next transaction (subscription) cannot start until the previous completes!)
  • concatAll
  • forkJoin
  • merge - Turn multiple Observables into a single observable.
  • mergeAll - Collect and subscribe to all observables.
  • race
  • startsWith
  • withLatestFrom
  • zip

Conditional

  • defaultIfEmpty
  • every
  • iif
  • sequenceequal

Creation

  • create
  • defer
  • empty
  • from - Turn an array, promise, or iterable into an observable.
  • fromEvent
  • interval - Emit numbers in sequence based on provided timeframe.
  • of - Emit variable amount of values in a sequence and then emits a complete notification.
  • range
  • throw
  • timer

Error Handling

  • catch / catchError - Gracefully handle errors in an observable sequence.
  • retry
  • retryWhen

Filtering

  • audit
  • auditTime
  • debounce
  • debounceTime
  • distinctUntilChanged
  • filter - Emit values that pass the provided condition.
  • first
  • ignoreElements
  • last
  • sample
  • single
  • skip - Skip the provided number of emitted values. (ignore the first x emissions from the source)
  • skipUntil
  • skipWhile
  • take - Emit provided number of values before completing. (When you are interested in only the first set number of emission)
  • takeUntil - Emit values until provided Observable emits.
  • takeWhile
  • throttle
  • throttleTime

Utility

  • do / tap - Transparently perform actions or side-effects, such as logging.
  • delay
  • delayWhen
  • finalize / finally
  • let
  • repeat
  • toPromise
  • timeout

Misc

  • throwError
  • Hot vs Cold Observables
  • A Producer is the source of values for your Observable (ex: Web Socket, DOM events, iterator, loop), observer.next(value)
import { Observable } from 'rxjs';

let observable = new Observable(subscriber => {
    subscriber.next(1);
    subscriber.next(2);
    subscriber.complete();
});

Promise

  • new Promise((resolve, reject) => reject('Rejected!'));

Multicasting

Each notification emitted by a single observable is received by multiple observers

  • multicast
  • publish
  • share
  • shareReplay

Transformation

Flattening - subscribing to an observable

someObservable = of(..)
someObservable.pipe(
 map(..)
)
.subscribe(result
 // observable
)

standalone

 someObservable.pipe(
  map(..),
  mergeAll
 )

mapping + flattening:

 someObservable.pipe(
  mergeMap()
 )
  • buffer
  • bufferCount
  • bufferTime
  • bufferToggle
  • bufferWhen
  • concatMap - Queue every observable, subscribe only when last observable completes "Wait In Line". (does not subscribe to the next observable until the previous completes)
  • concatMapTo
  • expand
  • exhaustMap - IGNORES new observables while current is emitting values "Do Not Disturb"
  • groupBy
  • map
  • mapTo
  • mergeMap / flatMap - Keep subscribing to every new observable "No strategy, Lazy". (more than one inner subscription maintained)
  • partition
  • pluck
  • reduce
  • scan
  • switchMap - Unsubscribe from last observable when a NEW one arrives - "Latest & Greatest" (maintains only one inner subscription at a time)
  • toArray
  • window
  • windowCount
  • windowTime
  • windowToggle
  • windowWhen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment