liveBook · Manning

Unidirectional data pipeline

As explained in The Joy of JavaScript

Unidirectional data flow is an architecture in which data moves in one direction through a system from source to sink.

A unidirectional data pipeline moves data in one direction from a source to a destination. In JavaScript, streams and promises support this architecture; an Observable models a lazy, push-based source that waits for a subscriber before transmitting data. section 1.0 section 9.4.1

An Observable pipeline separates data production, transformation, observation, and cleanup:

  • The Observable provides the conduit through which data flows downstream from its source. section 9.4.1
  • Operators can alter the flow’s course, speed, or other characteristics as data travels toward its destination. section 9.4.1
  • The Observer receives events through next, error, and complete operations. section 9.4.1
  • The Subscription exposes unsubscribe so consumers can stop generation-specific work, such as clearing an interval. section 9.4.1
Listing 9.14 Creating and subscribing to an Observable
const obs$ = Observable.of('The', 'Joy', 'of', 'JavaScript');
 
const subs = obs$.subscribe({
   next: ::console.log            #1
});
 
subs.unsubscribe();

Create an Observable from several values, subscribe a consumer to receive each value, then unsubscribe from the resulting stream. section 9.4.1

How The Joy of JavaScript covers it

How deep it goes
Explains Observable flow, laziness, operators, observers, subscriptions, and cancellation, but does not detail operator implementations.
Examples
Demonstrates Observable.of with four words, subscription through next, and explicit unsubscription.
What it assumes
Assumes JavaScript familiarity while teaching the Observable, Observer, Subscription, and lazy push-based flow model.
What you can do after
Apply the pattern via Observable, Observer, and Subscription abstractions to create, consume, and stop push-based data flows.
How it connects
Connects unidirectional flow with promises, streams, Observables, Observers, Subscriptions, operators, and modular application design.

Also explained in

Compare how 2 books explain unidirectional data pipeline →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Joy of JavaScript. The section links point to the parts of the book it draws on.