message: replace ratelimitedfunc with lodash impl
diff: @@ -20,54 +20,28 @@ limitations under the License.
  * to update the interface once for all of them.
  *
  * Note that the function must not take arguments, since the args
  - * could be different for each invocarion of the function.
  + * could be different for each invocation of the function.
  *
  * The returned function has a 'cancelPendingCall' property which can be called
  * on unmount or similar to cancel any pending update.
  */
  -module.exports = function(f, minIntervalMs) {
  - this.lastCall = 0;
  - this.scheduledCall = undefined;
  - const self = this;
  - const wrapper = function() {
  - const now = Date.now();
  -
  - if (self.lastCall < now - minIntervalMs) {
  - f.apply(this);
  - // get the time again now the function has finished, so if it
  - // took longer than the delay time to execute, it doesn't
  - // immediately become eligible to run again.
  - self.lastCall = Date.now();
  - } else if (self.scheduledCall === undefined) {
  - self.scheduledCall = setTimeout(
  - () => {
  - self.scheduledCall = undefined;
  - f.apply(this);
  - // get time again as per above
  - self.lastCall = Date.now();
  - },
  - (self.lastCall + minIntervalMs) - now,
  - );
  - }
  - };
  -
  - // add the cancelPendingCall property
  - wrapper.cancelPendingCall = function() {
  - if (self.scheduledCall) {
  - clearTimeout(self.scheduledCall);
  - self.scheduledCall = undefined;
  - }
  - };
  -
  - // make sure that cancelPendingCall is copied when react rebinds the
  - // wrapper
  - const _bind = wrapper.bind;
  - wrapper.bind = function() {
  - const rebound = _bind.apply(this, arguments);
  - rebound.cancelPendingCall = wrapper.cancelPendingCall;
  - return rebound;
  +import { throttle } from "lodash";
  +
  +export default function ratelimitedfunc(fn, time) {
  + const throttledFn = throttle(fn, time, {
  + leading: true,
  + trailing: true,
  + });
  + const _bind = throttledFn.bind;
  + throttledFn.bind = function() {
  + const boundFn = _bind.apply(throttledFn, arguments);
  + boundFn.cancelPendingCall = throttledFn.cancelPendingCall;
  + return boundFn;
  };
  - return wrapper;
  + throttledFn.cancelPendingCall = function() {
  + throttledFn.cancel();
  };
  + return throttledFn;
  +}
  