简单、函数式、强大。
通过纯函数和优雅组合体验响应式编程。
轻松创建和转换流
- 纯函数式方法
- 惰性执行模型
- TypeScript 优先设计
- 轻量且高性能
import { of, pipeFrom, map, filter, take } from 'rx4u';
// Create a stream from values
const numbers$ = of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
// Compose operators with pipeFrom
const result$ = pipeFrom(
numbers$,
filter(x => x % 2 === 0), // Keep even numbers
map(x => x * 2), // Double each
take(3) // Take first 3
);
// Subscribe to the stream
result$(
value => console.log(value), // 4, 8, 12
error => console.error(error),
() => console.log('Complete!')
);几秒钟即可开始
使用喜欢的包管理器安装 rx4u,立即开始构建响应式应用。
npm install rx4upnpm add rx4uyarn add rx4urx4u vs RxJS
了解 rx4u 的函数式方法与传统面向对象响应式编程的区别。
RxJS(面向对象)
import { of, map, filter, take } from 'rxjs';
const numbers$ = of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
const result$ = numbers$.pipe(
filter(x => x % 2 === 0),
map(x => x * 2),
take(3)
);
result$.subscribe(
value => console.log(value),
error => console.error(error),
() => console.log('Complete!')
);rx4u(函数式)
import { of, pipeFrom, map, filter, take } from 'rx4u';
const numbers$ = of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
const result$ = pipeFrom(
numbers$,
filter(x => x % 2 === 0),
map(x => x * 2),
take(3)
);
result$(
value => console.log(value),
error => console.error(error),
() => console.log('Complete!')
);纯函数
无需类和继承
TypeScript 优先
完整类型推导
轻量且高性能
极小的包体积
为什么选择 rx4u?
高性能
针对速度优化,开销极低且高效使用内存。
类型安全
基于 TypeScript 构建,提供出色的 IDE 支持和编译期安全性。
函数式设计
纯函数和可组合操作符带来可预测的行为。
响应式状态
内置 createState 和 createLazyState,实现响应式状态管理。
内存安全
取消订阅时自动清理,不保留隐藏引用。
摇树优化
按需导入,未使用的操作符会在构建时移除。