Skip to content

Instantly share code, notes, and snippets.

@davidgg
Created November 7, 2019 12:22
Show Gist options
  • Save davidgg/491a2084984b5eb09f8c348b84cf8d31 to your computer and use it in GitHub Desktop.
Save davidgg/491a2084984b5eb09f8c348b84cf8d31 to your computer and use it in GitHub Desktop.
RxJS

RxJS Introduction

What

RxJS allows us to manage and manipulate streams of data.

Theory

RxJS is the JS implementation of Reactive X, an API for asynchronous programming with observable streams.

It implements ideas from the Observer pattern, the Iterator pattern and functional programming.

In summary, a tool to:

  • Create event streams
  • Combine streams
  • Subscribe to the events of the streams

Key aspects:

  • Functional. Avoid stateful programs, using functions.
  • Operators. Set of operators that reduce lines of code.
  • Better async error handling.
  • Concurrency.

It's used in Angular extensively inside the core API and third-party libraries, but it's not mandatory. There are many implementations of it in different languages and frameworks.

Essential concepts

  • Observable. The object that listen to changes in the stream of data. Something that can be observed.
  • Observer. Represents the collection of listeners that are subscribed to the stream.
  • Subscription. The execution of an observable and observer.
  • Operators. Pure functions that manipulate the stream.
  • Subject. The stream emitter.

Marble Diagrams

Images that help us understand how a stream of data is manipulated. It has an input timeline with the original stream, middle operators that perform operations on it, and the output stream.

Marble Diagram

The catch operator:

Catch Operator

How

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment