【问题标题】:Difference Rxjs and .pipe [duplicate]Rxjs和.pipe的区别[重复]
【发布时间】:2019-06-24 14:48:38
【问题描述】:

谁能解释一下 rxjs 和 .pipe 的区别?

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

【问题讨论】:

标签: rxjs pipe


【解决方案1】:
  • RxJs 是一个库。根据 RxJs 文档-

RxJs 是一个使用 observable 进行反应式编程的库,它使 编写异步或基于回调的代码更容易

  • 管道是 RxJs 的一项功能。根据角度 文档-

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

管道在行动-

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

【讨论】:

  • 谢谢,现在清楚一点了。我只是 Angular 的新手。
【解决方案2】:

Rxjs 是一个用于 javascript official doc 的响应式扩展库

.Pipe 它是这个库example of native js pipeofficial rxjs docs 的一个函数

Web to learn rxjs

【讨论】:

    猜你喜欢
    • 2018-12-18
    • 2014-12-26
    • 2015-11-14
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    • 2021-11-07
    相关资源
    最近更新 更多