-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] New flatten map operators implementation #3149
Comments
Hi @ghetolay
The lack of named arguments for |
Humm I failed to explain it clearly, the idea is not to remove all the operators and only export that one. It's to replace all operators implementation with an alias to that one like it's currently done for Once we build and test that operator the only thing left to think about is the Now maybe I'm still wrong but that's what I was talking about. |
It seems like we can do this with |
I can't really see how. |
In order to get a better knowledge of the base code and challenges related to this issue I made a quick implementation of it. I was able to pass all unit tests (couldn't run perf tests) but I used some hacks; I just wanted to pass all tests by any means for the moment. During this playtime I found that current API has some unattended limitations.
The OP is about 3.b, but the current API is a 3.a. I really think we can get to 3.b : reduce the code base, extend the possibilities with a nice API; all that with minimal perfomance impact. If I could just get that approval, I'll then rework the API, submit it here and build PRs for 1, 2, 3. |
Closing due to lack of interest. |
From that @dorus's comment, I think we can merge the implementation of all the flatten map operators: mergeMap, concatMap, switchMap, exhaustMap, debounce/audiMap (#1777) into a single operator, flexible enough to cover all scenarios.
Then each of those operators would just be an alias of that main operator. Plus it may open new possibilities like the debounce/auditMap that doesn't exist yet.
I'll use
flatMap
andQueue
because it's hard to find new meaningful names and it's not worth spending too much time on it at this stage.Signature
The new
flatMap
operator becomes just some kind of shell doing operator related stuff like managing inner/outer observable but it won't take any decision anymore about what to subscribe to or cancel. Those decisions will be delegated toqueue
which is a simple interface decorrelated from rxjs internals to make it accessible for users.Queue will be composed of 2 functions, analog to push & pop but specific to our case.
Those functions will be called :
The algorithm of flatMap will then be as follow :
source emits
, depending on the queue implementation, do zero or more of :inner completion
, depending on the queue implementation, either :source completion
,inner emits
,inner error
andouter unsubscribe
:Queue Interface
As you can see it's fairly simple (except the tuple maybe), straightforward and easy for users to implements. It's all just about items, and nothing about rx stuff like subscriptions.
We can easily build a concurrent queue, buffer queue, priority queue etc...
Variant operators
With those 2
queue
implementations :We can now express and export all existings flatten operators as an alias :
flatMap(project, NoQueue)
flatMap(project, new ConcurrentFifoQueue(1))
(default buffersize being infinity).flatMap(project, new ConcurrentFifoQueue(1, 0))
(default drop being drop item).onNewItem(item: any, actives: any[]) => actives.length > 0 ? undefined : item
flatMap(project, new ConcurrentFifoQueue(1, 0, true))
onNewItem(item: any, actives: any[]) => [item, actives.length - 1]
flatMap(project, new ConcurrentFifoQueue(1, 1))
Pro/cons
Pro :
Con:
onNewItem
signature is not the sexiest API cause of the tuple, I tried removing it but ended up with even more complicated API.Thanks
Thanks @Dorus for all your time spent :)
The text was updated successfully, but these errors were encountered: