[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6JB2FJAQYYN9DW4ET18NY5P":3,"skill-same:01M6JB2FJAQYYN9DW4ET18NY5P":70},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":43,"commitSha":44,"skillDirectory":45,"forksCount":13,"repositoryHtmlUrl":46,"repositoryHomepageUrl":6,"ownerHtmlUrl":47,"ownerBlogUrl":6,"ownerDescription":48,"updatedAt":49,"install":50,"resources":63},"01M6JB2FJAQYYN9DW4ET18NY5P","rxjs-patterns-for-angular",null,"Implement RxJS patterns for reactive programming in Angular. Use this skill when working with Observables, operators, subscriptions, async data flows, and error handling. Covers common patterns like combineLatest, switchMap, debounceTime, catchError, retry logic, and integration with Angular Signals using toSignal() and toObservable(). Ensures proper subscription cleanup with takeUntilDestroyed().","superhealth\u002Fskills-hub","superhealth","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F6292112?v=4","01M6JA6E7F21BYK5W3E4P270TT","01M6JA6EC0W8MPHKDJVBZDSEZ0",0,"MIT","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002F7spade\u002Frxjs-patterns-for-angular\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"for","angular","rxjs patterns for angular","patterns","signals","angular signals","retry","with","flows","error","operators","logic","implement","async","use","programming","common","data","error handling","cleanup","2026-11-10 10:12:30",false,"---\nname: rxjs-patterns-for-angular\ndescription: \"Implement RxJS patterns for reactive programming in Angular. Use this skill when working with Observables, operators, subscriptions, async data flows, and error handling. Covers common patterns like combineLatest, switchMap, debounceTime, catchError, retry logic, and integration with Angular Signals using toSignal() and toObservable(). Ensures proper subscription cleanup with takeUntilDestroyed().\"\nlicense: \"MIT\"\n---\n\n# RxJS Patterns for Angular Skill\n\nThis skill helps implement reactive patterns using RxJS in Angular applications.\n\n## Core Principles\n\n### Modern Angular + RxJS\n- **Signals First**: Use Signals for state, RxJS for async operations\n- **Auto Cleanup**: Use `takeUntilDestroyed()` for subscription management\n- **Interop**: Use `toSignal()` and `toObservable()` for Signal\u002FObservable conversion\n- **AsyncPipe**: Prefer AsyncPipe in templates when not using Signals\n\n### Key Concepts\n- Observables for async data streams\n- Operators for data transformation\n- Subscription management and cleanup\n- Error handling and retry logic\n\n## Signal + RxJS Integration\n\n### toSignal() - Observable to Signal\n\n```typescript\nimport { Component, inject } from '@angular\u002Fcore';\nimport { toSignal } from '@angular\u002Fcore\u002Frxjs-interop';\nimport { HttpClient } from '@angular\u002Fcommon\u002Fhttp';\n\n@Component({\n  selector: 'app-task-list',\n  template: `\n    @if (tasks(); as taskList) {\n      @for (task of taskList; track task.id) {\n        \u003Cdiv>{{ task.title }}\u003C\u002Fdiv>\n      }\n    }\n  `\n})\nexport class TaskListComponent {\n  private http = inject(HttpClient);\n  \n  \u002F\u002F Convert Observable to Signal\n  tasks = toSignal(\n    this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks'),\n    { initialValue: [] }\n  );\n}\n```\n\n### toObservable() - Signal to Observable\n\n```typescript\nimport { Component, signal } from '@angular\u002Fcore';\nimport { toObservable } from '@angular\u002Fcore\u002Frxjs-interop';\nimport { switchMap } from 'rxjs\u002Foperators';\n\n@Component({\n  selector: 'app-search',\n  template: `\n    \u003Cinput \n      nz-input \n      [ngModel]=\"searchQuery()\" \n      (ngModelChange)=\"searchQuery.set($event)\" \n    \u002F>\n    \n    @if (results(); as resultList) {\n      @for (result of resultList; track result.id) {\n        \u003Cdiv>{{ result.name }}\u003C\u002Fdiv>\n      }\n    }\n  `\n})\nexport class SearchComponent {\n  searchQuery = signal('');\n  \n  \u002F\u002F Convert Signal to Observable and transform\n  private searchQuery$ = toObservable(this.searchQuery);\n  \n  results = toSignal(\n    this.searchQuery$.pipe(\n      debounceTime(300),\n      distinctUntilChanged(),\n      switchMap(query => this.searchService.search(query))\n    ),\n    { initialValue: [] }\n  );\n}\n```\n\n## Subscription Management\n\n### takeUntilDestroyed() - Auto Cleanup\n\n```typescript\nimport { Component, inject, signal, DestroyRef } from '@angular\u002Fcore';\nimport { takeUntilDestroyed } from '@angular\u002Fcore\u002Frxjs-interop';\nimport { interval } from 'rxjs';\n\n@Component({\n  selector: 'app-timer',\n  template: `\u003Cdiv>Time: {{ time() }}\u003C\u002Fdiv>`\n})\nexport class TimerComponent {\n  private destroyRef = inject(DestroyRef);\n  time = signal(0);\n  \n  constructor() {\n    \u002F\u002F Subscription automatically cleaned up on component destroy\n    interval(1000)\n      .pipe(takeUntilDestroyed(this.destroyRef))\n      .subscribe(value => this.time.set(value));\n  }\n}\n```\n\n### Manual Cleanup (Legacy Pattern - Avoid)\n\n```typescript\n\u002F\u002F ❌ DON'T: Manual subscription management (old pattern)\nexport class LegacyComponent implements OnDestroy {\n  private subscription = new Subscription();\n  \n  ngOnInit() {\n    this.subscription.add(\n      this.dataService.getData().subscribe(data => {\n        \u002F\u002F handle data\n      })\n    );\n  }\n  \n  ngOnDestroy() {\n    this.subscription.unsubscribe();\n  }\n}\n\n\u002F\u002F ✅ DO: Use takeUntilDestroyed()\nexport class ModernComponent {\n  private destroyRef = inject(DestroyRef);\n  data = signal\u003Cany>(null);\n  \n  constructor() {\n    this.dataService.getData()\n      .pipe(takeUntilDestroyed(this.destroyRef))\n      .subscribe(data => this.data.set(data));\n  }\n}\n```\n\n## Common Operators\n\n### switchMap - Switch to New Observable\n\n```typescript\n\u002F\u002F Switch to new search on every query change\nsearchResults$ = this.searchQuery$.pipe(\n  debounceTime(300),\n  switchMap(query => this.http.get(`\u002Fapi\u002Fsearch?q=${query}`))\n);\n```\n\n### mergeMap - Merge Multiple Observables\n\n```typescript\n\u002F\u002F Process all tasks in parallel\nprocessTasks$ = this.tasks$.pipe(\n  mergeMap(tasks => \n    from(tasks).pipe(\n      mergeMap(task => this.processTask(task))\n    )\n  )\n);\n```\n\n### concatMap - Process Sequentially\n\n```typescript\n\u002F\u002F Process tasks one by one in order\nprocessTasks$ = this.tasks$.pipe(\n  concatMap(tasks =>\n    from(tasks).pipe(\n      concatMap(task => this.processTask(task))\n    )\n  )\n);\n```\n\n### debounceTime - Debounce Input\n\n```typescript\n\u002F\u002F Wait 300ms after user stops typing\nsearch$ = this.searchInput$.pipe(\n  debounceTime(300),\n  distinctUntilChanged(),\n  switchMap(query => this.searchService.search(query))\n);\n```\n\n### distinctUntilChanged - Skip Duplicates\n\n```typescript\n\u002F\u002F Only emit when value actually changes\nstatus$ = this.statusSubject$.pipe(\n  distinctUntilChanged()\n);\n```\n\n### filter - Filter Values\n\n```typescript\n\u002F\u002F Only emit non-empty strings\nnonEmptySearch$ = this.searchQuery$.pipe(\n  filter(query => query.trim().length > 0),\n  switchMap(query => this.search(query))\n);\n```\n\n### map - Transform Values\n\n```typescript\n\u002F\u002F Transform task to display format\ntaskDisplay$ = this.task$.pipe(\n  map(task => ({\n    title: task.title,\n    status: task.status.toUpperCase(),\n    dueDate: formatDate(task.dueDate)\n  }))\n);\n```\n\n### tap - Side Effects\n\n```typescript\n\u002F\u002F Log without transforming\ntasks$ = this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks').pipe(\n  tap(tasks => console.log('Loaded tasks:', tasks.length)),\n  tap(tasks => this.analyticsService.track('tasks_loaded'))\n);\n```\n\n## Combining Observables\n\n### combineLatest - Wait for All\n\n```typescript\nimport { combineLatest } from 'rxjs';\n\n\u002F\u002F Combine multiple observables\nviewModel$ = combineLatest([\n  this.tasks$,\n  this.users$,\n  this.settings$\n]).pipe(\n  map(([tasks, users, settings]) => ({\n    tasks,\n    users,\n    settings\n  }))\n);\n\n\u002F\u002F Convert to Signal\nviewModel = toSignal(this.viewModel$);\n```\n\n### forkJoin - Wait for All to Complete\n\n```typescript\nimport { forkJoin } from 'rxjs';\n\n\u002F\u002F Load multiple resources in parallel\nloadAll$ = forkJoin({\n  tasks: this.taskService.getTasks(),\n  users: this.userService.getUsers(),\n  projects: this.projectService.getProjects()\n}).pipe(\n  map(({ tasks, users, projects }) => ({\n    tasks,\n    users,\n    projects\n  }))\n);\n```\n\n### merge - Merge Multiple Streams\n\n```typescript\nimport { merge } from 'rxjs';\n\n\u002F\u002F Combine multiple event streams\nallEvents$ = merge(\n  this.createEvent$,\n  this.updateEvent$,\n  this.deleteEvent$\n).pipe(\n  tap(event => this.handleEvent(event))\n);\n```\n\n### zip - Pair Up Values\n\n```typescript\nimport { zip } from 'rxjs';\n\n\u002F\u002F Pair up matching values from two streams\npaired$ = zip(\n  this.stream1$,\n  this.stream2$\n).pipe(\n  map(([value1, value2]) => ({ value1, value2 }))\n);\n```\n\n## Error Handling\n\n### catchError - Handle Errors\n\n```typescript\ntasks$ = this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks').pipe(\n  catchError(error => {\n    console.error('Failed to load tasks:', error);\n    this.notificationService.error('Failed to load tasks');\n    return of([]); \u002F\u002F Return empty array as fallback\n  })\n);\n```\n\n### retry - Retry on Failure\n\n```typescript\ntasks$ = this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks').pipe(\n  retry(3), \u002F\u002F Retry up to 3 times\n  catchError(error => {\n    console.error('Failed after 3 retries:', error);\n    return of([]);\n  })\n);\n```\n\n### retryWhen - Conditional Retry with Backoff\n\n```typescript\nimport { retryWhen, delay, scan, throwError } from 'rxjs';\n\ntasks$ = this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks').pipe(\n  retryWhen(errors =>\n    errors.pipe(\n      scan((retryCount, error) => {\n        if (retryCount >= 3) {\n          throw error; \u002F\u002F Max retries reached\n        }\n        console.log(`Retry ${retryCount + 1}\u002F3`);\n        return retryCount + 1;\n      }, 0),\n      delay(1000) \u002F\u002F Wait 1 second between retries\n    )\n  ),\n  catchError(error => {\n    console.error('Failed after retries:', error);\n    return of([]);\n  })\n);\n```\n\n## Real-Time Data\n\n### interval - Periodic Updates\n\n```typescript\nimport { interval, switchMap } from 'rxjs';\n\n\u002F\u002F Poll every 30 seconds\nliveData$ = interval(30000).pipe(\n  startWith(0), \u002F\u002F Emit immediately\n  switchMap(() => this.http.get('\u002Fapi\u002Flive-data')),\n  takeUntilDestroyed(this.destroyRef)\n);\n\nliveData = toSignal(this.liveData$);\n```\n\n### WebSocket Pattern\n\n```typescript\nimport { webSocket } from 'rxjs\u002FwebSocket';\n\nexport class RealtimeService {\n  private socket$ = webSocket('wss:\u002F\u002Fapi.example.com\u002Fws');\n  \n  messages$ = this.socket$.pipe(\n    catchError(error => {\n      console.error('WebSocket error:', error);\n      return EMPTY;\n    }),\n    retry({ delay: 5000 }) \u002F\u002F Reconnect after 5 seconds\n  );\n  \n  sendMessage(msg: any): void {\n    this.socket$.next(msg);\n  }\n}\n```\n\n## Loading States\n\n### Share Loading State\n\n```typescript\nimport { shareReplay } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class TaskService {\n  private http = inject(HttpClient);\n  \n  \u002F\u002F Cache and share the result\n  tasks$ = this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks').pipe(\n    shareReplay({ bufferSize: 1, refCount: true })\n  );\n}\n```\n\n### Loading Indicator Pattern\n\n```typescript\n@Component({\n  selector: 'app-task-list',\n  template: `\n    @if (loading()) {\n      \u003Cnz-spin \u002F>\n    } @else if (error()) {\n      \u003Cnz-alert nzType=\"error\" [nzMessage]=\"error()!\" \u002F>\n    } @else {\n      @for (task of tasks(); track task.id) {\n        \u003Cdiv>{{ task.title }}\u003C\u002Fdiv>\n      }\n    }\n  `\n})\nexport class TaskListComponent {\n  private taskService = inject(TaskService);\n  private destroyRef = inject(DestroyRef);\n  \n  loading = signal(false);\n  error = signal\u003Cstring | null>(null);\n  tasks = signal\u003CTask[]>([]);\n  \n  constructor() {\n    this.loadTasks();\n  }\n  \n  loadTasks(): void {\n    this.loading.set(true);\n    this.error.set(null);\n    \n    this.taskService.tasks$\n      .pipe(takeUntilDestroyed(this.destroyRef))\n      .subscribe({\n        next: (tasks) => {\n          this.tasks.set(tasks);\n          this.loading.set(false);\n        },\n        error: (err) => {\n          this.error.set(err.message || 'Failed to load tasks');\n          this.loading.set(false);\n        }\n      });\n  }\n}\n```\n\n## Advanced Patterns\n\n### Throttle vs Debounce\n\n```typescript\nimport { throttleTime, debounceTime } from 'rxjs';\n\n\u002F\u002F Throttle: Emit first, then ignore for duration\nthrottled$ = this.clicks$.pipe(\n  throttleTime(1000) \u002F\u002F Max once per second\n);\n\n\u002F\u002F Debounce: Wait for quiet period\ndebounced$ = this.input$.pipe(\n  debounceTime(300) \u002F\u002F Wait 300ms after last input\n);\n```\n\n### Scan - Accumulate Values\n\n```typescript\n\u002F\u002F Running total\ntotal$ = this.amounts$.pipe(\n  scan((acc, value) => acc + value, 0)\n);\n\n\u002F\u002F History accumulation\nhistory$ = this.events$.pipe(\n  scan((history, event) => [...history, event], [] as Event[])\n);\n```\n\n### startWith - Initial Value\n\n```typescript\n\u002F\u002F Start with loading state\nstatus$ = this.dataLoad$.pipe(\n  map(() => 'loaded'),\n  startWith('loading')\n);\n```\n\n### pairwise - Previous + Current\n\n```typescript\n\u002F\u002F Compare with previous value\nchanges$ = this.value$.pipe(\n  pairwise(),\n  map(([prev, curr]) => ({\n    previous: prev,\n    current: curr,\n    diff: curr - prev\n  }))\n);\n```\n\n## Best Practices\n\n### ✅ DO\n\n```typescript\n\u002F\u002F Use toSignal() for reactive data in templates\ndata = toSignal(this.data$, { initialValue: [] });\n\n\u002F\u002F Use takeUntilDestroyed() for cleanup\nthis.data$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe();\n\n\u002F\u002F Use switchMap for user-triggered requests\nsearch$ = this.query$.pipe(switchMap(q => this.search(q)));\n\n\u002F\u002F Handle errors explicitly\ndata$ = this.http.get('\u002Fapi\u002Fdata').pipe(\n  catchError(err => of(null))\n);\n```\n\n### ❌ DON'T\n\n```typescript\n\u002F\u002F Don't forget to unsubscribe\nthis.data$.subscribe(); \u002F\u002F Memory leak!\n\n\u002F\u002F Don't use nested subscribes\nthis.data$.subscribe(data => {\n  this.process(data).subscribe(); \u002F\u002F Anti-pattern!\n});\n\n\u002F\u002F Don't use async pipe with signals\n@if (data$ | async) { } \u002F\u002F Use signals instead\n```\n\n## Checklist\n\nWhen using RxJS:\n\n- [ ] Use toSignal() to convert Observables to Signals\n- [ ] Use takeUntilDestroyed() for subscription cleanup\n- [ ] Handle errors with catchError()\n- [ ] Debounce user input (300ms)\n- [ ] Use switchMap for cancellable requests\n- [ ] Share expensive Observables with shareReplay()\n- [ ] Provide initial values with startWith()\n- [ ] Filter out empty\u002Fnull values\n- [ ] Test async operations\n- [ ] Document complex operator chains\n\n## References\n\n- [RxJS Documentation](https:\u002F\u002Frxjs.dev\u002F)\n- [Angular Signals + RxJS Interop](https:\u002F\u002Fangular.dev\u002Fguide\u002Fsignals\u002Frxjs-interop)\n- [RxJS Operators](https:\u002F\u002Frxjs.dev\u002Fguide\u002Foperators)\n- [Learn RxJS](https:\u002F\u002Fwww.learnrxjs.io\u002F)\n","# RxJS Patterns for Angular Skill\n\nThis skill helps implement reactive patterns using RxJS in Angular applications.\n\n## Core Principles\n\n### Modern Angular + RxJS\n- **Signals First**: Use Signals for state, RxJS for async operations\n- **Auto Cleanup**: Use `takeUntilDestroyed()` for subscription management\n- **Interop**: Use `toSignal()` and `toObservable()` for Signal\u002FObservable conversion\n- **AsyncPipe**: Prefer AsyncPipe in templates when not using Signals\n\n### Key Concepts\n- Observables for async data streams\n- Operators for data transformation\n- Subscription management and cleanup\n- Error handling and retry logic\n\n## Signal + RxJS Integration\n\n### toSignal() - Observable to Signal\n\n```typescript\nimport { Component, inject } from '@angular\u002Fcore';\nimport { toSignal } from '@angular\u002Fcore\u002Frxjs-interop';\nimport { HttpClient } from '@angular\u002Fcommon\u002Fhttp';\n\n@Component({\n  selector: 'app-task-list',\n  template: `\n    @if (tasks(); as taskList) {\n      @for (task of taskList; track task.id) {\n        \u003Cdiv>{{ task.title }}\u003C\u002Fdiv>\n      }\n    }\n  `\n})\nexport class TaskListComponent {\n  private http = inject(HttpClient);\n  \n  \u002F\u002F Convert Observable to Signal\n  tasks = toSignal(\n    this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks'),\n    { initialValue: [] }\n  );\n}\n```\n\n### toObservable() - Signal to Observable\n\n```typescript\nimport { Component, signal } from '@angular\u002Fcore';\nimport { toObservable } from '@angular\u002Fcore\u002Frxjs-interop';\nimport { switchMap } from 'rxjs\u002Foperators';\n\n@Component({\n  selector: 'app-search',\n  template: `\n    \u003Cinput \n      nz-input \n      [ngModel]=\"searchQuery()\" \n      (ngModelChange)=\"searchQuery.set($event)\" \n    \u002F>\n    \n    @if (results(); as resultList) {\n      @for (result of resultList; track result.id) {\n        \u003Cdiv>{{ result.name }}\u003C\u002Fdiv>\n      }\n    }\n  `\n})\nexport class SearchComponent {\n  searchQuery = signal('');\n  \n  \u002F\u002F Convert Signal to Observable and transform\n  private searchQuery$ = toObservable(this.searchQuery);\n  \n  results = toSignal(\n    this.searchQuery$.pipe(\n      debounceTime(300),\n      distinctUntilChanged(),\n      switchMap(query => this.searchService.search(query))\n    ),\n    { initialValue: [] }\n  );\n}\n```\n\n## Subscription Management\n\n### takeUntilDestroyed() - Auto Cleanup\n\n```typescript\nimport { Component, inject, signal, DestroyRef } from '@angular\u002Fcore';\nimport { takeUntilDestroyed } from '@angular\u002Fcore\u002Frxjs-interop';\nimport { interval } from 'rxjs';\n\n@Component({\n  selector: 'app-timer',\n  template: `\u003Cdiv>Time: {{ time() }}\u003C\u002Fdiv>`\n})\nexport class TimerComponent {\n  private destroyRef = inject(DestroyRef);\n  time = signal(0);\n  \n  constructor() {\n    \u002F\u002F Subscription automatically cleaned up on component destroy\n    interval(1000)\n      .pipe(takeUntilDestroyed(this.destroyRef))\n      .subscribe(value => this.time.set(value));\n  }\n}\n```\n\n### Manual Cleanup (Legacy Pattern - Avoid)\n\n```typescript\n\u002F\u002F ❌ DON'T: Manual subscription management (old pattern)\nexport class LegacyComponent implements OnDestroy {\n  private subscription = new Subscription();\n  \n  ngOnInit() {\n    this.subscription.add(\n      this.dataService.getData().subscribe(data => {\n        \u002F\u002F handle data\n      })\n    );\n  }\n  \n  ngOnDestroy() {\n    this.subscription.unsubscribe();\n  }\n}\n\n\u002F\u002F ✅ DO: Use takeUntilDestroyed()\nexport class ModernComponent {\n  private destroyRef = inject(DestroyRef);\n  data = signal\u003Cany>(null);\n  \n  constructor() {\n    this.dataService.getData()\n      .pipe(takeUntilDestroyed(this.destroyRef))\n      .subscribe(data => this.data.set(data));\n  }\n}\n```\n\n## Common Operators\n\n### switchMap - Switch to New Observable\n\n```typescript\n\u002F\u002F Switch to new search on every query change\nsearchResults$ = this.searchQuery$.pipe(\n  debounceTime(300),\n  switchMap(query => this.http.get(`\u002Fapi\u002Fsearch?q=${query}`))\n);\n```\n\n### mergeMap - Merge Multiple Observables\n\n```typescript\n\u002F\u002F Process all tasks in parallel\nprocessTasks$ = this.tasks$.pipe(\n  mergeMap(tasks => \n    from(tasks).pipe(\n      mergeMap(task => this.processTask(task))\n    )\n  )\n);\n```\n\n### concatMap - Process Sequentially\n\n```typescript\n\u002F\u002F Process tasks one by one in order\nprocessTasks$ = this.tasks$.pipe(\n  concatMap(tasks =>\n    from(tasks).pipe(\n      concatMap(task => this.processTask(task))\n    )\n  )\n);\n```\n\n### debounceTime - Debounce Input\n\n```typescript\n\u002F\u002F Wait 300ms after user stops typing\nsearch$ = this.searchInput$.pipe(\n  debounceTime(300),\n  distinctUntilChanged(),\n  switchMap(query => this.searchService.search(query))\n);\n```\n\n### distinctUntilChanged - Skip Duplicates\n\n```typescript\n\u002F\u002F Only emit when value actually changes\nstatus$ = this.statusSubject$.pipe(\n  distinctUntilChanged()\n);\n```\n\n### filter - Filter Values\n\n```typescript\n\u002F\u002F Only emit non-empty strings\nnonEmptySearch$ = this.searchQuery$.pipe(\n  filter(query => query.trim().length > 0),\n  switchMap(query => this.search(query))\n);\n```\n\n### map - Transform Values\n\n```typescript\n\u002F\u002F Transform task to display format\ntaskDisplay$ = this.task$.pipe(\n  map(task => ({\n    title: task.title,\n    status: task.status.toUpperCase(),\n    dueDate: formatDate(task.dueDate)\n  }))\n);\n```\n\n### tap - Side Effects\n\n```typescript\n\u002F\u002F Log without transforming\ntasks$ = this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks').pipe(\n  tap(tasks => console.log('Loaded tasks:', tasks.length)),\n  tap(tasks => this.analyticsService.track('tasks_loaded'))\n);\n```\n\n## Combining Observables\n\n### combineLatest - Wait for All\n\n```typescript\nimport { combineLatest } from 'rxjs';\n\n\u002F\u002F Combine multiple observables\nviewModel$ = combineLatest([\n  this.tasks$,\n  this.users$,\n  this.settings$\n]).pipe(\n  map(([tasks, users, settings]) => ({\n    tasks,\n    users,\n    settings\n  }))\n);\n\n\u002F\u002F Convert to Signal\nviewModel = toSignal(this.viewModel$);\n```\n\n### forkJoin - Wait for All to Complete\n\n```typescript\nimport { forkJoin } from 'rxjs';\n\n\u002F\u002F Load multiple resources in parallel\nloadAll$ = forkJoin({\n  tasks: this.taskService.getTasks(),\n  users: this.userService.getUsers(),\n  projects: this.projectService.getProjects()\n}).pipe(\n  map(({ tasks, users, projects }) => ({\n    tasks,\n    users,\n    projects\n  }))\n);\n```\n\n### merge - Merge Multiple Streams\n\n```typescript\nimport { merge } from 'rxjs';\n\n\u002F\u002F Combine multiple event streams\nallEvents$ = merge(\n  this.createEvent$,\n  this.updateEvent$,\n  this.deleteEvent$\n).pipe(\n  tap(event => this.handleEvent(event))\n);\n```\n\n### zip - Pair Up Values\n\n```typescript\nimport { zip } from 'rxjs';\n\n\u002F\u002F Pair up matching values from two streams\npaired$ = zip(\n  this.stream1$,\n  this.stream2$\n).pipe(\n  map(([value1, value2]) => ({ value1, value2 }))\n);\n```\n\n## Error Handling\n\n### catchError - Handle Errors\n\n```typescript\ntasks$ = this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks').pipe(\n  catchError(error => {\n    console.error('Failed to load tasks:', error);\n    this.notificationService.error('Failed to load tasks');\n    return of([]); \u002F\u002F Return empty array as fallback\n  })\n);\n```\n\n### retry - Retry on Failure\n\n```typescript\ntasks$ = this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks').pipe(\n  retry(3), \u002F\u002F Retry up to 3 times\n  catchError(error => {\n    console.error('Failed after 3 retries:', error);\n    return of([]);\n  })\n);\n```\n\n### retryWhen - Conditional Retry with Backoff\n\n```typescript\nimport { retryWhen, delay, scan, throwError } from 'rxjs';\n\ntasks$ = this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks').pipe(\n  retryWhen(errors =>\n    errors.pipe(\n      scan((retryCount, error) => {\n        if (retryCount >= 3) {\n          throw error; \u002F\u002F Max retries reached\n        }\n        console.log(`Retry ${retryCount + 1}\u002F3`);\n        return retryCount + 1;\n      }, 0),\n      delay(1000) \u002F\u002F Wait 1 second between retries\n    )\n  ),\n  catchError(error => {\n    console.error('Failed after retries:', error);\n    return of([]);\n  })\n);\n```\n\n## Real-Time Data\n\n### interval - Periodic Updates\n\n```typescript\nimport { interval, switchMap } from 'rxjs';\n\n\u002F\u002F Poll every 30 seconds\nliveData$ = interval(30000).pipe(\n  startWith(0), \u002F\u002F Emit immediately\n  switchMap(() => this.http.get('\u002Fapi\u002Flive-data')),\n  takeUntilDestroyed(this.destroyRef)\n);\n\nliveData = toSignal(this.liveData$);\n```\n\n### WebSocket Pattern\n\n```typescript\nimport { webSocket } from 'rxjs\u002FwebSocket';\n\nexport class RealtimeService {\n  private socket$ = webSocket('wss:\u002F\u002Fapi.example.com\u002Fws');\n  \n  messages$ = this.socket$.pipe(\n    catchError(error => {\n      console.error('WebSocket error:', error);\n      return EMPTY;\n    }),\n    retry({ delay: 5000 }) \u002F\u002F Reconnect after 5 seconds\n  );\n  \n  sendMessage(msg: any): void {\n    this.socket$.next(msg);\n  }\n}\n```\n\n## Loading States\n\n### Share Loading State\n\n```typescript\nimport { shareReplay } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class TaskService {\n  private http = inject(HttpClient);\n  \n  \u002F\u002F Cache and share the result\n  tasks$ = this.http.get\u003CTask[]>('\u002Fapi\u002Ftasks').pipe(\n    shareReplay({ bufferSize: 1, refCount: true })\n  );\n}\n```\n\n### Loading Indicator Pattern\n\n```typescript\n@Component({\n  selector: 'app-task-list',\n  template: `\n    @if (loading()) {\n      \u003Cnz-spin \u002F>\n    } @else if (error()) {\n      \u003Cnz-alert nzType=\"error\" [nzMessage]=\"error()!\" \u002F>\n    } @else {\n      @for (task of tasks(); track task.id) {\n        \u003Cdiv>{{ task.title }}\u003C\u002Fdiv>\n      }\n    }\n  `\n})\nexport class TaskListComponent {\n  private taskService = inject(TaskService);\n  private destroyRef = inject(DestroyRef);\n  \n  loading = signal(false);\n  error = signal\u003Cstring | null>(null);\n  tasks = signal\u003CTask[]>([]);\n  \n  constructor() {\n    this.loadTasks();\n  }\n  \n  loadTasks(): void {\n    this.loading.set(true);\n    this.error.set(null);\n    \n    this.taskService.tasks$\n      .pipe(takeUntilDestroyed(this.destroyRef))\n      .subscribe({\n        next: (tasks) => {\n          this.tasks.set(tasks);\n          this.loading.set(false);\n        },\n        error: (err) => {\n          this.error.set(err.message || 'Failed to load tasks');\n          this.loading.set(false);\n        }\n      });\n  }\n}\n```\n\n## Advanced Patterns\n\n### Throttle vs Debounce\n\n```typescript\nimport { throttleTime, debounceTime } from 'rxjs';\n\n\u002F\u002F Throttle: Emit first, then ignore for duration\nthrottled$ = this.clicks$.pipe(\n  throttleTime(1000) \u002F\u002F Max once per second\n);\n\n\u002F\u002F Debounce: Wait for quiet period\ndebounced$ = this.input$.pipe(\n  debounceTime(300) \u002F\u002F Wait 300ms after last input\n);\n```\n\n### Scan - Accumulate Values\n\n```typescript\n\u002F\u002F Running total\ntotal$ = this.amounts$.pipe(\n  scan((acc, value) => acc + value, 0)\n);\n\n\u002F\u002F History accumulation\nhistory$ = this.events$.pipe(\n  scan((history, event) => [...history, event], [] as Event[])\n);\n```\n\n### startWith - Initial Value\n\n```typescript\n\u002F\u002F Start with loading state\nstatus$ = this.dataLoad$.pipe(\n  map(() => 'loaded'),\n  startWith('loading')\n);\n```\n\n### pairwise - Previous + Current\n\n```typescript\n\u002F\u002F Compare with previous value\nchanges$ = this.value$.pipe(\n  pairwise(),\n  map(([prev, curr]) => ({\n    previous: prev,\n    current: curr,\n    diff: curr - prev\n  }))\n);\n```\n\n## Best Practices\n\n### ✅ DO\n\n```typescript\n\u002F\u002F Use toSignal() for reactive data in templates\ndata = toSignal(this.data$, { initialValue: [] });\n\n\u002F\u002F Use takeUntilDestroyed() for cleanup\nthis.data$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe();\n\n\u002F\u002F Use switchMap for user-triggered requests\nsearch$ = this.query$.pipe(switchMap(q => this.search(q)));\n\n\u002F\u002F Handle errors explicitly\ndata$ = this.http.get('\u002Fapi\u002Fdata').pipe(\n  catchError(err => of(null))\n);\n```\n\n### ❌ DON'T\n\n```typescript\n\u002F\u002F Don't forget to unsubscribe\nthis.data$.subscribe(); \u002F\u002F Memory leak!\n\n\u002F\u002F Don't use nested subscribes\nthis.data$.subscribe(data => {\n  this.process(data).subscribe(); \u002F\u002F Anti-pattern!\n});\n\n\u002F\u002F Don't use async pipe with signals\n@if (data$ | async) { } \u002F\u002F Use signals instead\n```\n\n## Checklist\n\nWhen using RxJS:\n\n- [ ] Use toSignal() to convert Observables to Signals\n- [ ] Use takeUntilDestroyed() for subscription cleanup\n- [ ] Handle errors with catchError()\n- [ ] Debounce user input (300ms)\n- [ ] Use switchMap for cancellable requests\n- [ ] Share expensive Observables with shareReplay()\n- [ ] Provide initial values with startWith()\n- [ ] Filter out empty\u002Fnull values\n- [ ] Test async operations\n- [ ] Document complex operator chains\n\n## References\n\n- [RxJS Documentation](https:\u002F\u002Frxjs.dev\u002F)\n- [Angular Signals + RxJS Interop](https:\u002F\u002Fangular.dev\u002Fguide\u002Fsignals\u002Frxjs-interop)\n- [RxJS Operators](https:\u002F\u002Frxjs.dev\u002Fguide\u002Foperators)\n- [Learn RxJS](https:\u002F\u002Fwww.learnrxjs.io\u002F)\n",{"name":5,"license":14,"description":7},"master","08cc2532077058aa50e6e18f54695bc256c88152","skills\u002F7spade\u002Frxjs-patterns-for-angular","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub","https:\u002F\u002Fgithub.com\u002Fsuperhealth","java engineer","2026-04-06 22:07:23",{"source":8,"skillName":5,"commands":51,"prompt":61,"zipAvailable":62},[52,55,58],{"tool":53,"command":54},"npx","npx skills add superhealth\u002Fskills-hub --skill rxjs-patterns-for-angular",{"tool":56,"command":57},"bunx","bunx skills add superhealth\u002Fskills-hub --skill rxjs-patterns-for-angular",{"tool":59,"command":60},"pnpm","pnpm dlx skills add superhealth\u002Fskills-hub --skill rxjs-patterns-for-angular","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002F7spade\u002Frxjs-patterns-for-angular\u002FSKILL.md",true,[64],{"path":65,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":68,"sourceHtmlUrl":69},"skill-report.json","REFERENCE","参考文档",17849,"https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002F7spade\u002Frxjs-patterns-for-angular\u002Fskill-report.json",[71,96,118,130,144,159],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":38},"01M6MC9F3WHV8S8FZ2W4TRB0FE","vercel-react-best-practices","React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React\u002FNext.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fzhanlincui\u002Fvercel-react-best-practices\u002FSKILL.md",[],[78,79,80,81,82,83,84,85,86,87,21,88,35,89,90,91,92,93,94,95],"react","vercel react best practices","best practices","vercel","react best practices","data fetching","code","triggers","pages","next","refactoring","Optimization","tasks","guidelines","react components","components","performance","writing",{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":38},"01M6MB8KWE1Q5A5KERR7RFTQWP","vue-testing-best-practices","Use for Vue.js testing. Covers Vitest, Vue Test Utils, component testing, mocking, testing patterns, and Playwright for E2E testing.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fvuejs-ai\u002Fvue-testing-best-practices\u002FSKILL.md",[],[103,104,105,80,106,107,108,109,110,32,111,21,112,113,18,114,115,116,117],"vue testing best practices","testing best practices","vue","testing","testing patterns","js","e2e","vitest","component","test","mocking","utils","e2e testing","github","playwright",{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":38},"01M6MB8GK06M6GA4KVYNDV1BZP","vue-router-best-practices","Vue Router 4 patterns, navigation guards, route params, and route-component lifecycle interactions.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fvuejs-ai\u002Fvue-router-best-practices\u002FSKILL.md",[],[80,105,125,126,127,21,128,129,111,116],"router","vue router best practices","route","navigation","lifecycle",{"skillNo":131,"name":132,"nameZh":6,"description":133,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":134,"categories":135,"keywords":136,"publishedAt":38},"01M6MB8DQF21TZMQ9XC3745ERW","vue-pinia-best-practices","Pinia stores, state management patterns, store setup, and reactivity with stores.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fvuejs-ai\u002Fvue-pinia-best-practices\u002FSKILL.md",[],[137,138,105,80,25,139,21,140,141,142,143,116],"vue pinia best practices","pinia","store","management","state","state management","setup",{"skillNo":145,"name":146,"nameZh":6,"description":147,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":148,"categories":149,"keywords":150,"publishedAt":38},"01M6MB8A7MC08747J9TV4GWQ9A","vue-options-api-best-practices","Vue 3 Options API style (data(), methods, this context). Each reference shows Options API solution only.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fvuejs-ai\u002Fvue-options-api-best-practices\u002FSKILL.md",[],[105,151,152,153,80,154,155,156,157,35,116,158],"options","vue options api best practices","api","methods","reference","only","context","style",{"skillNo":160,"name":161,"nameZh":6,"description":162,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":163,"categories":164,"keywords":165,"publishedAt":38},"01M6MB85ZTQC24Q04X49MM4YXN","vue-development-guides","A collection of best practices and tips for developing applications using Vue.js. This skill MUST be apply when developing, refactoring or reviewing Vue.js or Nuxt projects.","https:\u002F\u002Fgithub.com\u002Fsuperhealth\u002Fskills-hub\u002Fblob\u002Fmaster\u002Fskills\u002Fvuejs-ai\u002Fvue-development-guides\u002FSKILL.md",[],[166,105,167,168,116,169,170,18,171,172,173,108,88,174,175,80],"development","guides","vue development guides","tips","apply","project","nuxt","projects","collection","applications"]