RxJS 18 🟣 Cheatsheet
This cheatsheet provides a quick reference for core RxJS concepts, operator categories, and common patterns.
1. Creation Operators
Use these to start your streams.
| Operator | Usage | Emits |
|---|---|---|
of(1, 2, 3) | Static values | 1, 2, 3, then completes |
from([1, 2, 3]) | Array, Promise, or Iterable | Each item individually |
interval(1000) | Timer | 0, 1, 2… every second |
timer(1000) | Delay | 0 after 1s, then completes |
fromEvent(el, 'click') | DOM event | The event object |
new Subject() | Manual stream | Whatever you next() |
2. Flattening Operators (The “Concurrency” Models)
The most critical choice in any RxJS pipeline.
| Operator | Behavior | Best Used For |
|---|---|---|
mergeMap | Runs all inner streams in parallel | Independent tasks (e.g., uploading files) |
switchMap | Cancels previous inner stream | Typeahead, routing, search |
concatMap | Runs inner streams sequentially | Queued tasks (e.g., database writes) |
exhaustMap | Ignores new input until inner finishes | Login buttons, form submits |
3. Transformation & Filtering
Modify the data flow.
| Operator | Purpose |
|---|---|
map(v => v * 2) | Transforms values |
filter(v => v > 0) | Discards values that fail the check |
take(n) | Completes after N values |
debounceTime(300) | Ignores bursts, emits last after silence |
distinctUntilChanged | Only emits if value is different from last |
tap(v => console.log(v)) | Perform side effects (debugging, logging) |
4. Subjects (State Containers)
| Subject Type | Behavior |
|---|---|
Subject | Standard: new subscribers get nothing. |
BehaviorSubject(init) | Requires init value: replays current value to new subs. |
ReplaySubject(n) | Replays last N values to new subs. |
AsyncSubject | Emits only the last value on completion. |
5. Error Handling & Lifecycle
catchError((err, caught) => ...): Intercept errors, return a new observable to recover.retry(n): Resubscribes to source N times on error.finalize(() => ...): Runs oncompleteORerrorORunsubscribe. Perfect for cleanup.takeUntil(notifier$): The standard for “destroying” a stream when a component unmounts.
6. Combining Streams
| Operator | Behavior |
|---|---|
combineLatest([a$, b$]) | Emits when any input emits (requires all to have emitted once) |
merge(a$, b$) | Emits whenever any input emits |
forkJoin([a$, b$]) | Emits only when all complete (last values only) |
concat(a$, b$) | Emits a$ completely, then b$ |
7. Memory Leak Checklist (The “Don’t Leak” Rule)
- Every Subscription needs a Teardown:
- Use
takeUntil(destroy$)for long-lived components. - Use
finalize()for closing sockets/resources.
- Use
- Avoid Subscription Nesting:
- Never subscribe inside a subscribe. Use flattening operators (
mergeMap, etc.) instead.
- Never subscribe inside a subscribe. Use flattening operators (
- Check your Operators:
- If using
shareReplay, ensurerefCount: trueis set if you want the stream to clean up when subscribers leave.
- If using
8. Quick Pattern: Typeahead Search
const search$ = input$.pipe(
debounceTime(300),
distinctUntilChanged(),
switchMap(term => fetchApi(term).pipe(
catchError(() => of([])) // Prevent stream death
))
);
9. Quick Pattern: The Bridge (Angular/Signal)
// RxJS to Signal
const mySignal = toSignal(myObservable$, { initialValue: 0 });
// Signal to RxJS
const myObservable$ = toObservable(mySignal).pipe(
filter(val => val > 10)
);
10. The Scheduler Hierarchy (Task Timing)
queueScheduler: Synchronous trampoline (no delay).asapScheduler: Microtask (after current sync block, before paint).animationFrameScheduler: Browser frame (before paint).asyncScheduler: Timer (macrotask, after paint).
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!