liveBook · Manning

Reactive programming

As explained in Functional Programming in JavaScript

A programming paradigm centered on data flows and propagation of change, especially for responding to asynchronous or event-driven updates.

Reactive programming treats changing or asynchronous data as streams of ordered events over time. Instead of giving files, web requests, database queries, notifications, user input, collections, and strings separate control flows, it lets code observe them through one model: subscribe to a stream, transform its values, and react to results. section 8.4

This style is useful when event-handling code would otherwise mix input reading, cleanup, validation, state changes, and output in one callback. A reactive pipeline separates those jobs into small operations, so each incoming value flows through the same sequence of transformations. Functional reactive programming raises the abstraction level by treating events as logically independent units rather than exposing temporal implementation details. section 1.3 section 8.5

Validate input as an event stream

An imperative SSN handler reads the field on every key press, removes spaces and dashes, checks its length, and changes a valid flag. With Rx.Observable.fromEvent, the input becomes a stream: pluck its value, map a cleanup function, filter values whose length is nine, then subscribe to valid SSNs. Each step has one purpose, and invalid values never reach the final subscriber. section 1.3 section 8.4

RxJS pipelines commonly use these parts:

  • Create or lift a source into an observable, such as a number range, a promise, an event, or a collection. section 8.4
  • Transform or select emitted values with operations such as map and filter. section 8.4
  • Subscribe to receive next values, errors, and completion notifications. section 8.4
  • Flatten a stream when an asynchronous source produces further observable values, as with a JSON request followed by individual students. section 8.4
Figure 8.12. The process of applying functions filter and map from an observable sequence of numbers

This diagram makes the pipeline visible: values enter an observable sequence, filter removes unwanted values, and map transforms those that remain. section 8.4

Reactive programming builds on functional composition. Lazy generators similarly model data as values produced on demand and passed through pure higher-order functions, but observables add subscription and support asynchronous event sources. In JavaScript, chained calls make the flow readable while deferring the details of when values arrive. section 8.3 section 8.4

How Functional Programming in JavaScript covers it

How deep it goes
Explains observable streams and pipelines with map, filter, subscription, errors, completion, and asynchronous flattening without detailing implementation internals.
Examples
Uses number ranges, generated squares, SSN input validation, and filtering U.S. students returned from a JSON request.
What it assumes
Builds on functional map, composition, and the minimal monadic interface while introducing observables as the reactive model.
What you can do after
Apply it via RxJS to transform event, promise, collection, and service-call values through observable pipelines.
How it connects
Connects functional composition, higher-order functions, lazy generators, promises, iterators, and monads to asynchronous event processing.

Also explained in

Compare how 6 books explain reactive programming →

Related concepts

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