Debounce repeats last emission at completion
See original GitHub issueDebounce operator emits last value at completion, even though no event is delayed.
This is apparently due to the timer not being reset after firing: https://github.com/cujojs/most/blob/a88c3169d231bcfe6f780cbd1db94b3b304ff284/src/combinator/limit.js#L92
On call to end, this is interpreted as a pending event.
Expected result
Once a debounced event has fired, it should not fire on stream completion.
Actual Result
See codepen: https://codepen.io/corolla/pen/XVwGQY?editors=1012#0
Notice ‘foo’ outputted twice indicating emission on stream completion.
Versions
- most.js: 1.7.2
- Chrome 63
Steps to reproduce
Run code, observe foo emitting twice.
Code to reproduce
most
.never()
.startWith('foo')
.until(most.of().delay(1000))
.debounce(100)
.subscribe({
next: console.log,
complete: () => console.log('complete')
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
take() with debounceTime() takes the last element only
debounceTime will then wait 1000ms after the last emission is received and emit it. The order of your operators within the pipe matters....
Read more >Debouncing and Throttling Explained Through Examples
Debounce and throttle are two similar (but different!) techniques to control how many times we allow a function to be executed over time. ......
Read more >Drop and Delay Observable Emissions with RxJS debounce
While Delay time shifts each emission by one second, debounce waits for one second of silence, and then it emits the most recent...
Read more >Master RxJs: Debounce all but first | by Lars Holdaas - Medium
This inner Observable then completes, as take(1) forces completion after a single emission has passed through, and our subscription switches ...
Read more >RxJS debounce vs throttle vs audit vs sample — Difference ...
It can be set to emit the first and/or the last value in the given time window. Then it repeats this procedure.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rhartvig Cool, glad that works for you 👍
Yeah, I debated something similar, too. I’ll try to explain why I went with the current approach. The value stored in DebounceSink is mutable, and tracks the latest seen value, and the one stored in DebounceTask is immutable and represents the pending debounce value. The use case of the former is only for end, and the use case for the latter is to implement the actual debounce functionality. Those are subtly different intents, and I thought keeping them separate might be better.
That said, I think your idea is interesting. I hadn’t considered invoking the task manually. I’ll give it a bit more thought today.
In the meantime, I think we’ll release this as is, to get the bug fix out. If we decided to change the implementation, we can do that in another release.
Aha! Yes, you’re right. Thanks.