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 从公开仓库中收录这些内容。

举报或申请下架