shama / gaze

:crystal_ball: A globbing fs.watch wrapper built from the best parts of other fine watch libs.
MIT License
1.16k stars 167 forks source link

Ensure last event within `debounceDelay` window is emitted #231

Closed bengourley closed 7 years ago

bengourley commented 7 years ago

I came up against the issue in #142 where the last change event is discarded. This ensures that the last event will fire after some are debounced.

I used the test that @motemen created in #142 but I found a simpler way to implement the logic.

In the grand schema of things I think debouncing/throttling should be left up to the user (re: your comments @shama https://github.com/shama/gaze/pull/142#issuecomment-94080660) but since this is already inside the module I thought I'd fix the bug. Feel free to remove everything later :)

bengourley commented 7 years ago

I added another commit to implement the debounceImmediate: true|false option that decides whether an event should be emitted on the leading edge of the window (terminology borrowed from https://npm.im/debounce). This means that the internal debounce function is feature complete and usable. I set the default to true which means the existing behaviour is maintained.

bengourley commented 7 years ago

Closing because of failing test on various platforms and lack of activity.