- 主题:RxJS和async/await就差一个cancel?
well, sometimes we do not even need to cancel; we just have to discard
previous results. if we had an IO monad that is very restricted like it
is in haskell, such problems may simply disappear.
(i never used rxjs but bacon claimed to be similar so this example is bacon)
pageUrl
.flatMapLatest(routerFunction)
.onValue(page => React.render(dom, page));
when route changes, the stream for previous route may continue to produce
pages, but will be discarded. no need for explicit cancel.
imo what makes streams superior to promises is that they have stricter
combination rules, requires a subscriber to produce side effects, thereby
encouraging programmers to compose everything into a super large stream;
and when we do that, the ability to produce multiple values is naturally
needed.
【 在 facilitator (黄书中自有颜如玉 脸书中自有黄金屋) 的大作中提到: 】
: typescript的async/await也可以throw 不过这代价有点太高了吧
: 上面说的用户初始了动作又无法放弃 通常是造成UI遇到错误的重要原因
--
FROM 49.221.19.*
【 在 facilitator (黄书中自有颜如玉 脸书中自有黄金屋) 的大作中提到: 】
: react的render函数会check目标是否存在?
whole page in react, the outermost element is just like <body>.
: 但是假如你收到数据之后要做比较heavy的反序列化呢?虽然这种情形比较特殊,但是还是显示地cancel会比较省CPU。对于移动端来说还是有意义的。
if the parsing is a stream.map(parser), it is automatically skipped when
this stream is no longer subscribed.
--
FROM 116.226.234.*
【 在 facilitator (黄书中自有颜如玉 脸书中自有黄金屋) 的大作中提到: 】
: 不是吧
: RxJS的subscribe就是1-3个callback函数 从并无法推断其所属的Component是否还存在 js引擎的垃圾回收没有那么主动 callback函数的引用传递给了RxJS 就不会被回收 你要主动unsubscribe才能中止
when using flatMapLatest a new stream unsubscribes the previous stream.
: Angular的推荐做法就是在ngOnDestroy unsubscribe Rxjs
ng components do not compose like react components do, so there will be
many entry points from the dom. each entry point requires manual
subscription; react simply has less entry points.
but well, very few projects use react in this way.
--
FROM 49.221.19.*