middle: true with throttle
Maybe I misunderstood something, but the current default behaviour of middle: true seems a bit surprising to me.
Currently, if one calls the function for the first time, it will get invoked. Then, if the function gets called again while the delay is still in place, it will get deferred until the next time. And finally, if the function gets called after the delay is over, nothing seems to happen.
Here is a little snippet to reproduce this
x = throttle(() => console.log("called"), 1000) // throttle 1 second
x() // call x
setTimeout(() => {console.log("x doesn't happen"); x(); }, 5000) // call again in 5 seconds
I can reproduce.
Looking through the source the variable start should be reset to true sometime but doesn't happen.
Sorry I missed the OP somehow.
If anyone would like to tackle this as a contribution, PRs are welcome!
Hi @keithamus,
I have made a PR to fix this. #15