区别Rxjs和.pipe

时间:2019-01-31 07:40:49

标签: rxjs pipe

有人可以解释一下rxjs和.pipe之间的区别吗?

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

2 个答案:

答案 0 :(得分:0)

Rxjs是一个针对JavaScript official doc

的反应式扩展库

。将其库example of native js pipeofficial rxjs docs

的功能

Web to learn rxjs

答案 1 :(得分:0)

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

RxJs是用于使用可观察对象进行反应式编程的库,   编写异步或基于回调的代码更容易

  • 管道是RxJ的功能。根据角度 文档-
  

管道使您可以将多个功能组合为一个功能。的   pipe()函数将您想要的函数作为其参数   合并并返回一个新函数,该函数在执行时将运行   按顺序组成函数。

进行操作-

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));