Skip to content

Instantly share code, notes, and snippets.

@KavenTheriault
Last active November 24, 2018 16:54
Show Gist options
  • Save KavenTheriault/613a3a367ae7dd582467235ab79317f4 to your computer and use it in GitHub Desktop.
Save KavenTheriault/613a3a367ae7dd582467235ab79317f4 to your computer and use it in GitHub Desktop.
Angular `Observables` notes

Angular Observables notes

https://angular.io/guide/rx-library

  • A promise can be subcribed.
  • It will give an observable.
const secondsCounter = interval(1000);
secondsCounter.subscribe(n =>
  console.log(`It's been ${n} seconds since subscribing!`));
  • You can use multiple built-in Operators on observable
    • The map() method creates a new array with the results of calling a provided function on every element in the calling array.
    • The filter() method creates a new array with all elements that pass the test implemented by the provided function.
  • You can use pipes to link operators together.
const squareOdd = of(1, 2, 3, 4, 5)
  .pipe(
    filter(n => n % 2 !== 0),
    map(n => n * n)
  );
  • RxJS provides the catchError operator that lets you handle known errors in the observable recipe.

Operators

  • Creation from, fromPromise,fromEvent, of
  • Combination combineLatest, concat, merge, startWith , withLatestFrom, zip
  • Filtering debounceTime, distinctUntilChanged, filter, take, takeUntil
  • Transformation bufferTime, concatMap, map, mergeMap, scan, switchMap
  • Utility tap
  • Multicasting share
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment