Skip to content

v3.0.0

Latest
Compare
Choose a tag to compare
@devrelm devrelm released this 28 Aug 12:15
· 26 commits to master since this release

Build Status Coverage Status

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();