Added
- Throttled listeners can now be canceled (useful for cleanup):
var throttledListener = throttle(listener); window.addEventListener('resize', throttledListener); submitButton.addEventListener('click', () => { window.removeEventListener('resize', throttledListener); // prevent any queued calls from executing on the next animation frame: throttledListener.cancel(); })
Changed
- Updated types to use generics;
throttle
will now return a function
of the same type it was passed. - frame-throttle now runs in strict mode
Fixed
-
Binding a throttled listener with
.bind()
resulted in both the bound and
unbound listeners being throttled together.For instance, in the following scenario,
listener
was only being called once:var throttledListener = throttle(listener); var boundThrottledListener1 = throttledListener.bind(someContext); var boundThrottledListener2 = throttledListener.bind(anotherContext); throttledListener(); boundThrottledListener1(); boundThrottledListener2();