Rxjs: Proposal: add a switchScan operator

Created on 10 Oct 2017  路  7Comments  路  Source: ReactiveX/rxjs

It will be similar as the mergeScan but instead of merging all events of inner observables, if the outer source emitted a new event, it switch to the recently accumulated inner observable.

discussion feature

Most helpful comment

This just came up at Google... I'm going to reopen it.

Here's a minimal implementation in JS: http://jsbin.com/kiyoyir/3/edit?js,console

All 7 comments

while it is not concluded yet, we're discussing of plan for mergeScan itself (https://github.com/ReactiveX/rxjs/issues/2737) and for now, we recommend to create operator as user-level first instead of direct addition into core lib. (https://github.com/ReactiveX/rxjs/blob/master/doc/operator-creation.md#diy-custom-operators-for-end-users).

I have stumbled across a situation where a switchScan() would be perfect; implementing it myself does not sound like all that much fun.

@kylecordes is your scenario solved by just passing concurrency=1?

@bradleyayers I'm not sure - I ended up solving the problem I was having a completely different way, with a group operation plus a switch map.

This just came up at Google... I'm going to reopen it.

Here's a minimal implementation in JS: http://jsbin.com/kiyoyir/3/edit?js,console

Here's a minimal implementation in JS: http://jsbin.com/kiyoyir/3/edit?js,console

@benlesh I think you forgot of disposal of outer subscription in that demo.

Closing this in favour of #4442 - which has an associated PR and has been discussed in a core-team meeting.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chalin picture chalin  路  4Comments

dooreelko picture dooreelko  路  3Comments

Zzzen picture Zzzen  路  3Comments

jakovljevic-mladen picture jakovljevic-mladen  路  3Comments

marcusradell picture marcusradell  路  4Comments