Giter VIP home page Giter VIP logo

dissecting-rxjs's Introduction

《深入浅出RxJS》已经由机械工业出版社发行,这个repo存放的是书中所有的代码。

配合响应式编程(包括React和RxJS)的探讨,作者会在知乎专栏《进击的React》中持续更新,欢迎关注。

任何技术问题可以通过知乎私信或者值乎咨询,有问必答。

执行repo里的code,首先运行npm install安装对应依赖包,然后利用npx来执行对应的JavaScript文件,例如:

npx babel-node chapter-01/declarative/addOne.js

部分代码在浏览器中执行,用浏览器打开对应HTML文件即可。

alt text

dissecting-rxjs's People

Contributors

mocheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dissecting-rxjs's Issues

combineAll执行的问题

consoleWithTime('now')
const ho$ = interval(1000).pipe(
  take(2),
  map((x, i) => interval(1500).pipe(
    map(y => `(${i}) ${x} : ${y}`),
    take(3)
  )),
  combineAll()
)

ho$.subscribe(consoleWithTime)

执行结果

13:07:28.004 now
13:07:31.525 [ '(0) 0 : 0', '(1) 1 : 0' ] // (2 + 1.5)s
13:07:33.030 [ '(0) 0 : 1', '(1) 1 : 0' ] //**
13:07:33.031 [ '(0) 0 : 1', '(1) 1 : 1' ] //**
13:07:34.532 [ '(0) 0 : 2', '(1) 1 : 1' ] //**
13:07:34.532 [ '(0) 0 : 2', '(1) 1 : 2' ] //**

时序图


                                         0:0   0:1         0:1   0:2         0:2
                                         1:0   1:0         1:1   1:1         1:2
                                          ^     ^           ^     ^           ^
                                          |     |           |     |           |
                                          |     |           |     |           |
                                          |     |           |     |           |
                                          |     |           |     |           |
                                          +     |           +     |           +
                        +-----------------0-----------------1-----------------2------------------->
                        X                       |                 |
                        X                       |                 |
                        X                       +                 +
            +-----------------0-----------------1-----------------2------------------------------->
            X           X
            X           X
            X           X
+----- -----0----- -----1----- -----2----- -----3----- -----4----- -----5----- -----6----- ------->

注意输出里, **的那几行是同时输出的, 说明combineAll只是将最终map出来的所有流进行了combineLatest, 本例中就相当于直接combineLatest了两个interval(1500)

对比combineLatest和merge, combineAll和mergeAll的结果是不符合预期的

如果希望能按照3.5s, 4s, 5s, 5.5s, 6.5s时输出, 应该如何做?

Cannot read property 'isStopped' of undefined

不是本书的问题, 但是想请教一下作者

const source$ = Observable.create(({ next }) => {
  next(1)
  next(2)
  next(3)
})

source$.subscribe(console.log)

// 会报错误: TypeError: Cannot read property 'isStopped' of undefined
const source$ = Observable.create((observer) => {
  observer.next(1)
  observer.next(2)
  observer.next(3)
})

source$.subscribe(console.log)
// 运行正常: 1 2 3

不知作者知道内部到底是什么原因吗

maybe an error in Chapter 6 about ‘isEmpty’

isEmpty第一段示例代码,不是应该在吐出第一条数据的时候吐出false吗?书上写的true

const source$ = interval(10000);

const isEmpty$ = source$.pipe(
isEmpty()
);
isEmpty$
.subscribe(
console.log,
() => {
console.log('error');
},
() => {
console.log('complete');
}
);

// 10秒后
// false
// complete

感谢第一章的例子

感谢第一章的例子
让我重新想起来 <meta charset="utf-8">
被IDE养懒了,看到乱码一时竟忘记怎么设置 utf-8

笔误

PAGE37:
第二行
const cold$=
应该是
const hot$=

P49 的错误

merge 的代码中

import 'rxjs/add/operator/map'

其中,map 应该为 merge

[bug] P279 async asap queue 例子输出错误

书上给的输出和说明一看就不一致了。

before schedule
queue
after schedule
async
asap

又因为 asap 使用的是 Micro Task,所以它的任务会抢在 async 之前完成。

Some typos in book

  • 书中第二章,第37页例子
const producer = new �Producer()
const cold$ = new Observable(observer => {...})

这里应该为 hot$, 因为数据的产生与observable 是独立的。

  • 第39页代码例子第3行
mapped subscribe(console.log)

缺一个点

  • 48页第21行
上面代码导入的模块是node_modules/rxjs/add/observable/of.js, 其中的代码是再Observable的prototype属性上增加一个函数,

of 应该是静态操作符,应该是在Observable上添加of 方法,而不是prototype上。

第8章转换数据流关于windowCount的描述

184页顶部关于第一个参数与第二个参数的问题,“如果使用了第二个参数,那么第一个参数依然是时间区间的长度,但是每间隔第二个参数startWindowEvery的毫秒数,就会新开一个时间区间。”该描述与文档有出入,此方法两个参数与时间无关,与数量有关。
文档:
https://rxjs-dev.firebaseapp.com/api/operators/windowCount
https://cn.rx.js.org/class/es6/Observable.js~Observable.html#instance-method-windowCount

217页retry例子的描述

"还是利用throwOnUnlucky"来产生错误,retry的参数是3……第二次失败之后……",按理解来看retry的参数是2,"第二次失败之后"应该为"第二次重试失败之后",第二次失败之后会进行第二次重试,第三次失败之后会传递至catch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.