首页 > 其他分享 >Rxjs 入门

Rxjs 入门

时间:2023-07-24 22:22:11浏览次数:44  
标签:Rxjs 入门 map rxjs filter range Observable RxJS

RxJS(Reactive Extensions for JavaScript)是一个用于处理异步数据流和事件流的库。它是基于观察者模式和迭代器模式的一种实现,可以帮助开发者更方便地处理复杂的异步操作。
RxJS的核心概念是Observable(可观察对象)。Observable代表一个可观察的数据源,它可以发出多个值,并在完成或出错时终止。开发者可以通过订阅Observable来获取数据流,并使用各种操作符来对数据流进行处理。

RxJS Logo RxJS: Reactive Extensions For JavaScript

CI
npm version
Join the chat at https://gitter.im/Reactive-Extensions/RxJS

The Roadmap from RxJS 7 to 8

Curious what's next for RxJS? Follow along with Issue 6367.

RxJS 7

FOR 6.X PLEASE GO TO THE 6.x BRANCH

Reactive Extensions Library for JavaScript. This is a rewrite of Reactive-Extensions/RxJS and is the latest production-ready version of RxJS. This rewrite is meant to have better performance, better modularity, better debuggable call stacks, while staying mostly backwards compatible, with some breaking changes that reduce the API surface.

Apache 2.0 License

Versions In This Repository

  • master - This is all of the current work, which is against v7 of RxJS right now
  • 6.x - This is the branch for version 6.X

Most PRs should be made to master.

Important

By contributing or commenting on issues in this repository, whether you've read them or not, you're agreeing to the Contributor Code of Conduct. Much like traffic laws, ignorance doesn't grant you immunity.

Installation and Usage

ES6 via npm

npm install rxjs

It's recommended to pull in the Observable creation methods you need directly from 'rxjs' as shown below with range.
If you're using RxJS version 7.2 or above, you can pull in any operator you need from the same spot, 'rxjs'.

import { range, filter, map } from 'rxjs';

range(1, 200)
  .pipe(
    filter(x => x % 2 === 1),
    map(x => x + x)
  )
  .subscribe(x => console.log(x));

If you're using RxJS version below 7.2, you can pull in any operator you need from one spot, under 'rxjs/operators'.

import { range } from 'rxjs';
import { filter, map } from 'rxjs/operators';

range(1, 200)
  .pipe(
    filter(x => x % 2 === 1),
    map(x => x + x)
  )
  .subscribe(x => console.log(x));

CDN

For CDN, you can use unpkg:

https://unpkg.com/rxjs@^7/dist/bundles/rxjs.umd.min.js

The global namespace for rxjs is rxjs:

const { range } = rxjs;
const { filter, map } = rxjs.operators;

range(1, 200)
  .pipe(
    filter(x => x % 2 === 1),
    map(x => x + x)
  )
  .subscribe(x => console.log(x));

Goals

  • Smaller overall bundles sizes
  • Provide better performance than preceding versions of RxJS
  • To model/follow the Observable Spec Proposal to the observable
  • Provide more modular file structure in a variety of formats
  • Provide more debuggable call stacks than preceding versions of RxJS

Building/Testing

  • npm run compile build everything
  • npm test run tests
  • npm run dtslint run dtslint tests

标签:Rxjs,入门,map,rxjs,filter,range,Observable,RxJS
From: https://www.cnblogs.com/xiaojiuwow/p/17578470.html

相关文章

  • jQuery快速入门
    我们最好称之为是jQuery库更好一些,不要称之为是框架#库就类似于是Python中的模块,简称为jq#jQuery就是js、css等的封装版本,只要一封装,写法肯定会简单jQuery介绍jQuery是一个轻量级的、兼容多浏览器的JavaScript库。#他就是一个封装好的js文件,几十KB大小#前端的最大问题就......
  • jQuery快速入门
    jQuery库一般称之为jQuery库,不要称为框架,库类似于Python中的模块,简称jqjQuery就是js、css等的封装版,只要已封装,写法肯定简单一些 jQuery介绍jQuery是一个轻量级的、兼容多浏览器的JavaScript库。#他就是一个封装好的js文件,几十KB大小前端的最大问题就是兼容性问......
  • Node.js入门 - 永恒的Hello World!
    文章原作者为LeeJacobson,已经作者授权翻译用于非商业用途。介绍 这是我的关于Node.js系列入门教程的第一篇。必须说明一下,我并不是Node.js的专家,但是尝试向别人解释这是怎么回事是自我学习的一个好方法。如果你发现有些地方并不是那么正确,请提出来让我知道以便修正,谢之。 最近......
  • QT从入门到实战完整版 P38
    手动调用绘图事件widget.h#ifndefWIDGET_H#defineWIDGET_H#include<QWidget>QT_BEGIN_NAMESPACEnamespaceUi{classWidget;}QT_END_NAMESPACEclassWidget:publicQWidget{Q_OBJECTpublic:Widget(QWidget*parent=nullptr);~Widget();......
  • 从入门到高深,史上最全的Spark综合帖
     什么是SparkSpark是UC Berkeley AMP lab所开源的类Hadoop MapReduce的通用的并行计算框架,Spark基于map reduce算法实现的分布式计算,拥有Hadoop MapReduce所具有的优点;但不同于MapReduce的是Job中间输出和结果可以保存在内存中,从而不再需要读写HDFS,因此Spark能更好地适用于......
  • SpringBoot集成日志入门
    一、日志的作用程序中的日志是记录程序的运行情况,包括用户的各种操作、程序的运行状态等信息。类似于飞机的黑匣子。二、日志的级别表:日志级别及其描述日志级别描述OFF关闭:不输出日志FATAL致命:用于输出可能会导致应用程序终止的错误ERROR错误:用于输出程序的错误(这些错误不会导......
  • 记一次nacos注册中心搭建步骤(入门)
    1、下载nacos本操作步骤使用的是稳定版本2.1.1 下载地址:https://github.com/alibaba/nacos/releases/tag/2.1.1百度网盘下载地址:链接:https://pan.baidu.com/s/1w0CUkIpDJ8jI3N2FH3hKWw?pwd=af53提取码:af532、本次操作系统是linux(centos7) 上传到服务器指......
  • 入门篇-其之一-第一个Java程序
    ⚠️注意:本文中包含实际操作,需要安装JDK。如果需要安装JDK,请按照这篇文章的步骤进行安装:点我查看JDK安装教程小白可以多看几遍这篇文章,多敲几次代码前面我们已经安装了JDK,接下来就是写一个属于自己的Java程序了。用什么写自己的Java程序呢?有人说用IDEA、Eclipse等集成开发工......
  • spring6 ioc aop 从入门到精通零基础进阶学习路线?
    当你已经掌握了Spring框架的基础知识以及IoC和AOP的核心概念后,可以进一步深化你的学习。以下是更详细的学习路线:1.IoC容器进阶:-学习如何自定义Bean的初始化和销毁方法,并了解Bean生命周期的各个阶段。-深入了解Spring的作用域(Scope)概念,如单例模式、原型模式、会话模式和请求模......
  • Python入门 - 路径,文件夹
    路径#分隔符print(os.pathsep)#;print(os.altsep)#/print(os.extsep)#.#拼接print(os.path.join("a","b","c"))#a\b\c#绝对路径print(os.path.abspath("a/b/c"))#C:\Users\win\PycharmProjects\myTest\a\b\c......