什么是RxJS


本文作者: jsweibo

本文链接: https://jsweibo.github.io/2019/11/21/%E4%BB%80%E4%B9%88%E6%98%AFRxJS/

摘要

本文主要讲述了:

  1. 什么是 RxJS
  2. 规格
  3. 示例

正文

什么是 RxJS

RxJS 全称为”Reactive Extensions Library for JavaScript”,中文意思为“适用于 JavaScript 的响应式扩展库”。

规格

  • ES2015
  • CommonJS
  • UMD

示例

输入:

learn_rxjs/index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script src="https://unpkg.com/core-js-bundle/index.js"></script>
<script src="https://unpkg.com/regenerator-runtime/runtime.js"></script>
<script src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script src="https://unpkg.com/@reactivex/rxjs@6/dist/global/rxjs.umd.js"></script>
<script type="text/babel">
const observable = new rxjs.Observable(function (subscriber) {
subscriber.next(1);
subscriber.next(2);
subscriber.next(3);
});

observable.subscribe({
next(x) {
console.log(x);
},
});
</script>
</head>
<body></body>
</html>

输出:

1
2
3
1
2
3

参考资料

本文作者: jsweibo

本文链接: https://jsweibo.github.io/2019/11/21/%E4%BB%80%E4%B9%88%E6%98%AFRxJS/


本文对你有帮助?请支持我


支付宝
微信