差异Rxjs和.pipe

Difference Rxjs and .pipe

本问题已经有最佳答案,请猛点这里访问。

有人能解释一下RXJS和.pipe之间的区别吗?

每个例子都有助于理解这两种情况。在什么情况下我们可以使用每个案例?


  • RXJS是一个库。根据RXJS文档-

RxJs is a library for reactive programming using observables that makes
it easier to compose asynchronous or callback-based code

  • 管道是RXJS的一个特性。按角度文件-

Pipes let you combine multiple functions into a single function. The
pipe() function takes as its arguments the functions you want to
combine, and returns a new function that, when executed, runs the
composed functions in sequence.

作用中的管道-

1
2
3
4
5
6
7
8
9
10
import { filter, map } from 'rxjs/operators';

const squareOdd = of(1, 2, 3, 4, 5)
  .pipe(
    filter(n => n % 2 !== 0),
    map(n => n * n)
  );

// Subscribe to get values
squareOdd.subscribe(x => console.log(x));


RXJS是一个用于JavaScript官方文档的反应式扩展库

.pipe它是本机JS管道和官方RXJS文档的库示例的函数。

网络学习RXJS