Skip to content

About

Learn RxJS by doing — 16 runnable TypeScript ticks, from Observables to a backoff-with-jitter retry operator.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

RxJS Mental Model

A learn-by-doing tour of RxJS in 16 ticks, from "what is an Observable" to writing a production-grade backoffWithJitter retry operator. Each tick is a small directory: a runnable example, an exercise to solve, and a short doc. The goal isn't to memorize operators — it's to build the mental model: laziness, hot vs cold, flattening, error propagation, teardown, scheduling.

Getting started

npm install
npm run tick1:example   # run the concept demo               …  tickN:example
npm run tick1:task      # run the exercise / your solution    …  tickN:task
npm run typecheck       # tsc --noEmit across all ticks

Runtime: Node + tsx (no build step). Strict TypeScript.

The 16 ticks

# Topic Key idea
1 Observable, Observer, Subscription lazy streams; next/error/complete
2 Creation + pipe/map/filter of/from; operators are stream→stream
3 Async time — interval/take/tap take completes; operator order matters
4 Higher-order — switchMap/mergeMap flattening; cancel-latest vs keep-all
5 Subjects & hot vs cold multicast; BehaviorSubject replay
6 Combination — merge/combineLatest react to any; wait-for-all gotcha
7 withLatestFrom & zip trigger+context vs index pairing
8 Error handling — catchError/retry errors are terminal; blast radius
9 Marble testing virtual time; map preserves timing
10 shareReplay fetch once, share; refCount leak
11 scan vs reduce running vs final; reduce needs completion
12 debounceTime + distinctUntilChanged the type-ahead recipe
13 takeUntil teardown signal; finalize vs tap
14 Custom operators compose vs from-scratch; return the subscription
15 Schedulers sync default; micro- vs macrotask
16 Capstone — backoffWithJitter() reusable retry operator with jitter

CHEATSHEET.md is the one-page recap of all 16.

Anatomy of a tick

Each tickN/ directory holds three files:

  • example.ts — a small, runnable demo of the concept, with comments. Run npm run tickN:example.
  • task.ts — the exercise (a // YOUR TASK block). In the docs commit it's a scaffold ending in // write your code here; in the feat commit it holds the worked answer plus a // === Review === comment on why it works. Run npm run tickN:task.
  • tickN.md — the prose doc: concept · example · task · key takeaways.

Example and task are separate programs, so their console output never interleaves.

Commit ideology

The git history is meant to be replayable as a course. Conventional-commit prefixes, and two commits per tick:

  1. docs(tickN): … — concept, example, task scaffold Adds tickN/example.ts (the demo), tickN/task.ts (task + // write your code here), tickN/tickN.md, and the tickN:example / tickN:task npm scripts. Run npm run tickN:task to attempt it.
  2. feat(tickN): … — solution + cheatsheet Fills tickN/task.ts with the worked solution (=== Review === notes) and appends that tick's section to CHEATSHEET.md (header range grows Ticks 1–N).

Plus one chore: setup commit at the root (deps, base npm scripts, strict tsconfig, MIT license).

So the log reads top-to-bottom as: set up → learn tick 1 (read doc, run example, try task, see solution) → … → tick 16. git checkout <docs-commit> to practice; git diff <docs>..<feat> to compare your answer with the worked one.

Why these choices

  • Runnable over abstract — every concept is a program you can execute and modify, not a paragraph. Async behavior (timing, cancellation, scheduling) only really lands when you watch it.
  • Strict TypeScript — types catch the classic mistakes (e.g. calling a number method on a string) before runtime, which is half the lesson in several ticks.
  • One concept per tick — small enough to hold in your head; the cheatsheet stitches them together.

About

Learn RxJS by doing — 16 runnable TypeScript ticks, from Observables to a backoff-with-jitter retry operator.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages