staltz / xstream

An extremely intuitive, small, and fast functional reactive stream library for JavaScript
http://staltz.github.io/xstream/
MIT License
2.37k stars 137 forks source link

feat(debounce): emit pending value on completion #259

Closed xtianjohns closed 6 years ago

xtianjohns commented 6 years ago

Emit any pending value, then complete, if a source stream completes before a debounce interval closes.

Description

In order to be able to emit the latest value upon completion, the operator needs access to the most recent value. In the previous implementation, the emission took place in a closure created by setTimeout, so now the operator has a new property t which keeps track of this emission.

This value is cleared when the debounce interval closes and upon completion.

Resolve #257. Probably should close #127.

staltz commented 6 years ago

Looks good, @xtianjohns, but could you use the special object NO instead of null? Otherwise a stream that emits nulls (I use these sometimes) could not be correctly debounced.

xtianjohns commented 6 years ago

🤦‍♂️ It really has been awhile since I've worked on this - good catch @staltz.

xtianjohns commented 6 years ago

Also, let's hold off on a merge even if CI goes green, Travis failed for buffer (extra) should not emit empty buffers, but locally I've had two successes and one failure for sampleCombine (extra) should complete only when the sample stream has completed, and never the failure from Travis.

Dunno why I'm seeing flaky behavior, but I'm gonna try to puzzle it out.

staltz commented 6 years ago

Thanks!