Add overlapping option to flatMap#320
Open
bpinto wants to merge 1 commit into
Open
Conversation
This will cause the next stream to be added before any old streams are
removed.
```
const channelA = Kefir.stream((emitter) => {
console.log('connect a');
let count = 0, id = setInterval(() => emitter.value(count++), 250);
return () => { console.log('disconnect a'); clearInterval(id); };
});
const channelB = Kefir.stream((emitter) => {
console.log('connect b');
let count = 0, id = setInterval(() => emitter.value(count++), 250);
return () => { console.log('disconnect b'); clearInterval(id); };
});
const data = {
a: channelA,
b: Kefir.combine([channelA, channelB]),
c: channelB,
};
Kefir.sequentially(1000, ['a', 'b', 'c', undefined])
.flatMapLatest(p => p ? data[p] : Kefir.never())
.log('result');
```
With overlapping option disabled (default):
```
> connect a
> result <value> 0
> result <value> 1
> result <value> 2
> disconnect a
> connect a
> connect b
> result <value> [0, 0]
> result <value> [1, 0]
> result <value> [1, 1]
> result <value> [2, 1]
> result <value> [2, 2]
> disconnect a
> disconnect b
> connect b
> result <value> 0
> result <value> 1
> result <value> 2
> disconnect b
> result <end>
```
With overlapping option enabled:
```
> connect a
> result <value> 0
> result <value> 1
> result <value> 2
> connect b
> result <value> [3, 0]
> result <value> [3, 1]
> result <value> [4, 1]
> result <value> [4, 2]
> disconnect a
> result <value> 3
> result <value> 4
> result <value> 5
> disconnect b
> result <end>
```
Closes: kefirjs#235 kefirjs#236
Contributor
Author
|
This is my first time diving into kefir codebase so I most likely did something silly while trying to implement this feature. In any case, please let me know what you think! |
bpinto
commented
Aug 19, 2021
| Observable.prototype.flatMapLatest = function(fn) { | ||
| return new FlatMap(this, fn, {concurLim: 1, drop: 'old'}).setName(this, 'flatMapLatest') | ||
| Observable.prototype.flatMapLatest = function(fn, options = {}) { | ||
| options.concurLim = 1 |
Contributor
Author
There was a problem hiding this comment.
If only we had object rest spread... 😬
bpinto
commented
Aug 19, 2021
|
|
||
| describe('overlapping with a concurrency limit that has maxed out', () => { | ||
| describe('and with a queue limit', () => { | ||
| it('not maxed out, should add to the queue', () => { |
Contributor
Author
There was a problem hiding this comment.
All these "should add to the queue" tests are kinda silly because I can't really confirm that the queue has changed... not sure how to improve these tests.
bpinto
commented
Aug 19, 2021
|
|
||
| _removeCur(obs) { | ||
| if (this._active) { | ||
| _removeCur(obs, after) { |
Contributor
Author
There was a problem hiding this comment.
I don't like passing a boolean, not sure about performance impact, but wouldn't it be better to have two methods?
_removeCur and _removeCurWithDelayedUnsubscription
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This will cause the next stream to be added before any old streams are removed.
With overlapping option disabled (default):
With overlapping option enabled:
Closes: #235 #236