All files / fuse-ui-shared/decorators debounce.ts

100% Statements 8/8
50% Branches 1/2
100% Functions 3/3
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 241x                   2x 1x 1x 1x   2x         1x      
import * as _ from 'underscore';
/**
 * debounce decorator
 *
 * @debounce(delay: number, immediate: boolean = true)
 * action()  {
 *    // do some real work
 * }
 */
// tslint:disable:no-invalid-this
export function debounce(delay: number, Eimmediate: boolean = true) {
  return function (target: any, methodKey: string, descriptor: PropertyDescriptor) {
    let innerMethod = descriptor.value;
    descriptor.value = _.debounce(
      function () {
        return innerMethod.apply(this, arguments);
      },
      delay,
      immediate);
 
    return descriptor;
  };
}