agentleFS
itsmuskanagarwalitsmuskanagarwal/claude-pack/skills/rxjs-modernize/SKILL.md

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.

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
  1. Distinctive:

    Before (manual unsubscribe array, easy to forget a push):

    line 37
  2. Distinctive:

    After (when async pipe isn't viable — imperative subscription needed):

    line 46
  3. Distinctive:

    After — move transforms into the pipe, subscribe only assigns:

    line 61
  4. Distinctive:

    If no tests exist for the file being modernized, stop and route to characterization-tests first — Rx timing changes are exactly the kind of …

    line 73
  5. Very specific:

    Never default to switchMap for writes — cancelling an in-flight save silently drops data.

    line 79
  6. Very specific:

    Never leave a mergeMap without a comment justifying unordered concurrency is safe.

    line 81
  7. Distinctive:

    Never batch multiple recipe applications into one commit without an intermediate green test run.

    line 83

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md
<!-- owner: Muskan, added: 2026-07-16, model: claude-sonnet-5, review: quarterly -->

RxJS Modernize

Operator decision table (pick by intent, not habit)

SituationOperatorWhy
New request should cancel/replace an in-flight one (search-as-you-type, route param changes)switchMapCancels the stale inner subscription
Writes must preserve order (sequential saves)concatMapQueues, never interleaves
Independent parallel work, order doesn't mattermergeMapRequires a comment explaining why concurrency is safe here
Submit buttons / avoid duplicate in-flight triggersexhaustMapIgnores 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

  1. Identify every anti-pattern instance in the target file(s) before touching any of them (list file:line per instance).
  2. Apply one recipe at a time. Run tests after each individual change — don't batch multiple flattening changes into one untested edit.
  3. 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.
  4. Report before/after per instance and the test result after each.

Anti-patterns

  • Never default to switchMap for writes — cancelling an in-flight save silently drops data.
  • Never leave a mergeMap without a comment justifying unordered concurrency is safe.
  • Never batch multiple recipe applications into one commit without an intermediate green test run.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.