Skip to content

ericrisco/rsc-harness / skills/angular

angular

Verified

Use when building, refactoring, or debugging Angular (v20/21+): standalone components, signals, zoneless change detection, @if/@for/@defer control flow, inject() DI, resource()/httpResource(), RxJS interop, NgRx SignalStore, ng CLI. NOT React (that is react), NOT Next.js (that is nextjs), NOT a TypeScript language question (that is typescript).

FileKindSize
SKILL.mdskill md13.5 KB
evals/README.mdmarkdown72 B
evals/cases.yamlconfig2.0 KB
references/migration.mdmarkdown4.0 KB
references/signals-rxjs.mdmarkdown4.0 KB
scripts/verify.shexecutablescript4.2 KB

references/signals-rxjs.md

View on GitHub
# Signals vs RxJS — when to use which, and how to bridge

Signals and RxJS coexist in modern Angular. Signals are the default for UI state and
synchronous derivation; RxJS still owns asynchronous *streams* of events over time.

## Decision matrix

| You have… | Use | Why |
|-----------|-----|-----|
| A piece of UI state read in a template | `signal()` | Pull-based, glitch-free, drives zoneless CD directly |
| A value derived from other state | `computed()` | Memoized, lazy, no manual subscription |
| One async fetch tied to inputs | `httpResource()` / `resource()` | Gives `value/isLoading/error/reload`, auto-refetch, no leak |
| A stream over time (websocket, key events, intervals) | RxJS `Observable` | Signals are values-now, not events-over-time |
| Debounce / throttle / retry / cancel-in-flight | RxJS (`debounceTime`, `switchMap`, `retry`) | These are stream operators; signals have no time dimension |
| A writable copy that resets when a source changes | `linkedSignal()` | Purpose-built; avoids an effect-to-sync anti-pattern |

Rule of thumb: **state → signals, events → observables.** When in doubt, start with a signal;
escalate to RxJS only when you need an operator that models time.

## Interop

`toSignal()` and `toObservable()` are the two bridges (`@angular/core/rxjs-interop`).

```typescript
import { toSignal, toObservable, takeUntilDestroyed } from '@angular/core/rxjs-interop';

// Observable -> Signal: subscribe is managed for you; unsubscribes on destroy.
private search = signal('');
results = toSignal(
  toObservable(this.search).pipe(
    debounceTime(300),
    switchMap(q => this.api.search(q)),  // switchMap cancels the prior request
  ),
  { initialValue: [] as Result[] },
);
```

- `toSignal(obs$, { initialValue })` — read `results()` in the template; the subscription is
  cleaned up automatically when the injection context is destroyed.
- `toObservable(sig)` — turn a signal into a stream so you can apply operators. It emits on the
  microtask queue, not synchronously.
- `takeUntilDestroyed()` — for the rare hand-rolled subscription, this completes it when the
  component/service is destroyed. Use it instead of a manual `Subscription` + `ngOnDestroy`.

## effect() pitfalls

`effect()` is for side effects, not derivation. Common ways it goes wrong:

```typescript
// Pitfall 1 — infinite loop: an effect that writes a signal it also reads.
effect(() => this.count.set(this.count() + 1)); // re-runs forever

// Pitfall 2 — using an effect to derive state. Use computed() instead.
effect(() => this.total.set(this.qty() * this.price())); // double-fires, hidden graph
// Fix:
total = computed(() => this.qty() * this.price());

// Pitfall 3 — wanting to write without creating a dependency: wrap in untracked().
effect(() => {
  const id = this.userId();           // tracked dependency
  untracked(() => this.log.push(id)); // read/write here is NOT a dependency
});
```

- An effect runs once on creation and again whenever any signal it *reads* changes.
- Reading a signal inside `untracked(() => …)` does not register it as a dependency.
- If you find yourself calling `.set()` from inside an effect to feed the template, you almost
  certainly want `computed()` or `linkedSignal()`.

## resource() / httpResource() patterns

```typescript
// Dependent fetch: the resource re-runs when team() changes.
team = signal('eng');
users = httpResource<User[]>(() => `/api/users?team=${this.team()}`);

// Mutate then refresh:
async addUser(u: User) {
  await firstValueFrom(this.http.post('/api/users', u));
  this.users.reload();
}

// Loading / error in the template:
// @if (users.isLoading()) { <app-spinner/> }
// @else if (users.error()) { <p>Failed</p> }
// @else { @for (u of users.value(); track u.id) { … } }
```

- A `resource()` cancels the previous load when its `params` change (it passes an `AbortSignal`
  to the loader) — use it for `fetch` cancellation without writing RxJS.
- `httpResource()` is GET-oriented and reactive. For POST/PUT/DELETE keep `HttpClient` and call
  `reload()` after the mutation.
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall