rxjs-modernize
Skill0 starsChanged 4 months agoMITView on GitHub
Refactor RxJS anti-patterns — nested subscribes, wrong flattening operator, subscription leaks — into idiomatic, leak-safe code. Use whenever the user asks to clean up or modernize RxJS, when reviewing Angular code that nests subscribe() calls or manually manages subscriptions, or when frontend-review-checklist flags an Rx violation.
In this repository11 other files it gives its agents.
- angular-enterpriseSkill
- angular-migrationSkill
- characterization-testsSkill
- claude-md-architectSkill
- code-archaeologySkill
- feature-flag-changeSkill
- frontend-review-checklistSkill
- session-hygieneSkill
- session-stateSkill
- strangler-migrationSkill
- tdd-loopSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 5 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 37
Before (manual unsubscribe array, easy to forget a push):
- Distinctive: line 46
After (when async pipe isn't viable — imperative subscription needed):
- Distinctive: line 61
After — move transforms into the pipe, subscribe only assigns:
- Distinctive: line 73
If no tests exist for the file being modernized, stop and route to characterization-tests first — Rx timing changes are exactly the kind of …
- Very specific: line 79
Never default to switchMap for writes — cancelling an in-flight save silently drops data.
- Very specific: line 81
Never leave a mergeMap without a comment justifying unordered concurrency is safe.
- Distinctive: line 83
Never batch multiple recipe applications into one commit without an intermediate green test run.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- owner: Muskan, added: 2026-07-16, model: claude-sonnet-5, review: quarterly -->RxJS Modernize
Operator decision table (pick by intent, not habit)
| Situation | Operator | Why |
| New request should cancel/replace an in-flight one (search-as-you-type, route param changes) | switchMap | Cancels the stale inner subscription |
| Writes must preserve order (sequential saves) | concatMap | Queues, never interleaves |
| Independent parallel work, order doesn't matter | mergeMap | Requires a comment explaining why concurrency is safe here |
| Submit buttons / avoid duplicate in-flight triggers | exhaustMap | Ignores new triggers until the current one completes |
Recipe 1 — flatten nested subscribes
Before:
this.a$.subscribe(a => {
this.b(a).subscribe(b => {
this.c(b).subscribe(c => this.state = c);
});
});After:
this.a$.pipe(
switchMap(a => this.b(a)),
switchMap(b => this.c(b)),
).subscribe(c => this.state = c);Pick the operator per row above per level — don't default every level to switchMap without checking whether cancellation is actually correct there.
Recipe 2 — subscription leaks
Before (manual unsubscribe array, easy to forget a push):
this.subs.push(this.data$.subscribe(d => this.items = d));
// ngOnDestroy: this.subs.forEach(s => s.unsubscribe());After (preferred — template):
<div *ngFor="let item of items$ | async; trackBy: trackById">After (when async pipe isn't viable — imperative subscription needed):
this.data$.pipe(takeUntilDestroyed()).subscribe(d => this.items = d);Async pipe is the default; takeUntilDestroyed() is the fallback for
subscriptions that must live in a service or component method body.
Recipe 3 — logic in subscribe callbacks
Before:
this.data$.subscribe(d => {
const filtered = d.filter(x => x.active);
this.items = filtered.map(x => x.name);
});After — move transforms into the pipe, subscribe only assigns:
this.items$ = this.data$.pipe(
map(d => d.filter(x => x.active).map(x => x.name)),
);Procedure
- Identify every anti-pattern instance in the target file(s) before touching any of them (list file:line per instance).
- Apply one recipe at a time. Run tests after each individual change — don't batch multiple flattening changes into one untested edit.
- If no tests exist for the file being modernized, stop and route to characterization-tests first — Rx timing changes are exactly the kind of change that needs a behavior pin beforehand.
- Report before/after per instance and the test result after each.
Anti-patterns
- Never default to
switchMapfor writes — cancelling an in-flight save silently drops data. - Never leave a
mergeMapwithout a comment justifying unordered concurrency is safe. - Never batch multiple recipe applications into one commit without an intermediate green test run.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

