m-gagne / limit.js

JavaScript event/call debounce & limit helper
MIT License
177 stars 14 forks source link

Add an "immediate" argument #6

Open nbish11 opened 9 years ago

nbish11 commented 9 years ago

This parameter can be useful in a lot of situations, for example:

// Using MooTools here
// A simple user-activity script

document.body.addEvent('mousemove', function () {
    this.set('data-useractivity', true);
}.debounce(250, true));

document.body.addEvent('mousemove', function () {
    this.set('data-useractivity', false);
}.debounce(250, false));
m-gagne commented 9 years ago

This PR would change the order of parameters for debounce, also if we pull this in, it should also apply to the limit function as well (I'm hoping to keep functional parity between the two).

nbish11 commented 9 years ago

Hmmm, I see what you mean. While I could implement the immediate functionality to throttle(), it wouldn't really make sense if the immediate was required after context. Maybe it can be pulled into a future version?