Reactive Programming

aj-geddes/useful-ai-prompts/skills/reactive-programming

作者 aj-geddes3f5182cfd739無授權條款355 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫7 個月前更新

Implement reactive programming patterns using RxJS, streams, observables, and backpressure handling. Use when building event-driven UIs, handling async data streams, or managing complex data flows.

AI 產生的概覽

指導使用 RxJS、可觀察物件、資料流與背壓處理來實作反應式程式設計模式。

功能
此技能提供使用 RxJS 建構事件驅動應用程式的說明與參考指南,涵蓋可觀察物件、操作符、Subject、防抖搜尋、狀態管理、WebSocket 重新連線、多串流合併、背壓處理與自訂操作符,並附帶一個元件範本。它產出的是指引與程式碼範例,而非執行指令碼。
適用情境
適用於建構事件驅動介面、處理非同步資料流、管理複雜資料流,或處理 WebSocket、SSE 等即時更新的情境。
執行需求
不附指令碼,僅為說明與參考文件。使用其中的範例需要具備 TypeScript/JavaScript 專案並安裝 RxJS 套件。

Reactive Programming

Table of Contents

Overview

Build responsive applications using reactive streams and observables for handling asynchronous data flows.

When to Use

  • Complex async data flows
  • Real-time data updates
  • Event-driven architectures
  • UI state management
  • WebSocket/SSE handling
  • Combining multiple data sources

Quick Start

Minimal working example:

typescript
import {  Observable,  Subject,  BehaviorSubject,  fromEvent,  interval,} from "rxjs";import {  map,  filter,  debounceTime,  distinctUntilChanged,  switchMap,} from "rxjs/operators";
// Create observable from arrayconst numbers$ = new Observable<number>((subscriber) => {  subscriber.next(1);  subscriber.next(2);  subscriber.next(3);  subscriber.complete();});
numbers$.subscribe({  next: (value) => console.log(value),// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
RxJS Basics [blocked]RxJS Basics
Search with Debounce [blocked]Search with Debounce
State Management [blocked]State Management
WebSocket with Reconnection [blocked]WebSocket with Reconnection
Combining Multiple Streams [blocked]Combining Multiple Streams
Backpressure Handling [blocked]Backpressure Handling
Custom Operators [blocked]Custom Operators

Best Practices

✅ DO

  • Unsubscribe to prevent memory leaks
  • Use operators to transform data
  • Handle errors properly
  • Use shareReplay for expensive operations
  • Combine streams when needed
  • Test reactive code

❌ DON'T

  • Subscribe multiple times to same observable
  • Forget to unsubscribe
  • Use nested subscriptions
  • Ignore error handling
  • Make observables stateful

來源與署名

來源:aj-geddes/useful-ai-prompts位於skills/reactive-programming提交3f5182c

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架