English · Deutsch
Exercise repo for the workshop “Reactive programming with RxJS”. Every lesson has an exercise with a starting point, tests, and a reference solution. In the later exercises, a small workshop shop with product search and cart is the running example.
- Create and share Observables, and end every subscription cleanly
- Process and combine streams with operators, and catch errors
- Test time-dependent code with the
TestSchedulerwithout real waiting
- Node.js 26 –
nvm usein therxjs/folder reads the version fromrxjs/.nvmrc. - An editor with TypeScript support
git clone https://github.com/MikeBild/Reactive-Programming.git
cd Reactive-Programming/rxjs
nvm use
npm ci
npm run checknpm run check checks the types and runs all tests against the reference solutions. After that, everything is green.
Every exercise lives in rxjs/exercises/<lesson>/. The starting point index.ts contains the task and TODO comments, index.test.ts checks your code, and solution/ holds the reference solution for comparison. All commands run in the rxjs/ folder. How to run the tests, why they are red at first, and how solution mode works is described in rxjs/README.md.
The order follows the agenda of the workshop.
| Lesson | ID | Task |
|---|---|---|
| When is reactive programming worth it? | rx-why |
The project is set up. Note three features from your project where values arrive over time. |
| Push instead of pull | rx-push-pull |
Generator and Observable for one to ten. Who triggers the next value? |
| Nothing happens without subscribe | rx-observable-contract |
ticker(ms) with setInterval, complete after five values, teardown stops the timer. |
| Almost everything becomes an Observable | rx-creation |
Clicks, timer, and Promise as Observables, logged together with a prefix. Demo: node exercises/rx-creation/demo.ts |
| Operators are functions in a pipe | rx-operators-pipe |
Message processing: your own operators ofType and countOfType with filter, distinctUntilChanged, and scan. |
| Every subscription needs an end | rx-subscription-cleanup |
Three subscriptions, one destroy$, takeUntil, and finalize. |
| Which operator combines your streams? | rx-combining |
FizzBuzz without modulo: numbers and two cyclic streams via zip. |
| Cold or hot, who starts the producer? | rx-cold-hot |
Two subscribers, two requests. With share, only one. |
| Promises and Observables work together | rx-promises-async |
fromAbortable(task): unsubscribe triggers the abort. Plus firstValueFrom. |
| switchMap, mergeMap, concatMap, or exhaustMap? | rx-flattening |
Search, autosave, upload queue, and login with switchMap, concatMap, mergeMap, and exhaustMap, each choice justified. |
| An error ends the stream | rx-error-handling |
Three URLs with mergeMap, timeout, retry with backoff, and an error value via catchError. |
| Subjects share values, share shares work | rx-subjects-multicasting |
The last one turns off the light: one WebSocket connection with share and ref counting. Plus a CartStore with BehaviorSubject. |
| What if more events arrive than you can process? | rx-time-backpressure |
A sensor with a thousand values per second, live value via auditTime, average via bufferTime. Demo: node exercises/rx-time-backpressure/demo.ts |
| Testing time without waiting | rx-marble-testing |
Here you write the tests yourself with node:test, node:assert, and TestScheduler: interval without mocks and the product search from search.ts with marble diagrams. The starting point is search.test.ts with test.todo, run it with npm run test:marble. |
| Lesson | ID | Task |
|---|---|---|
| UI state as a stream of Actions | rx-ui-state |
Cart view model for the workshop shop: actions and scan, derived totalCents$ and canPlace$, plus the last five searches as an LRU list. |
| Signals or Observables? | rx-signals-interop |
Cart and total as a Signal, product search with debounceTime and switchMap as an Observable, plus the bridges toObservable and toSignal. |
- Workshop (held in German): “Reactive programming with RxJS”
- Slides: slides.mikebild.dev/introduction-reactive-programming.en
- PDF: introduction-reactive-programming.en.pdf
- Video: introduction-reactive-programming.en.mp4
The earlier material with C# and Rx.NET is kept unchanged in Examples/, together with the earlier slide deck (Reactive-Programming.pptx, Reactive-Programming.pdf) and the overview diagram overwiew.drawio.