All files / src/core method.ts

100% Statements 21/21
100% Branches 16/16
100% Functions 6/6
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 4910x                       12x 8x               12x 8x 8x 8x                 12x 8x               12x 8x 8x 8x      
import { _debounce, _throttle } from './lodash-tool'
 
/**
 * @ignore
 * 方法类
 */
 
/**
 * @ignore
 * 防抖函数
 * 默认调用在防抖开始后
 */
export function debounce(fn: any, delay = 500, option = {}) {
  return _debounce(fn, delay, option)
}
 
/**
 * @ignore
 * 防抖装饰器
 * 默认调用在防抖开始后
 */
export function debounceWrap(delay = 500, option = {}) {
  return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
    descriptor.value = _debounce(descriptor.value, delay, option)
    return descriptor
  }
}
 
/**
 * @ignore
 * 节流函数
 * 默认调用在节流开始前
 */
export function throttle(fn: any, delay = 500, option = {}) {
  return _throttle(fn, delay, option)
}
 
/**
 * @ignore
 * 节流装饰器
 * 默认调用在节流开始前
 */
export function throttleWrap(delay = 500, option = {}) {
  return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
    descriptor.value = _throttle(descriptor.value, delay, option)
    return descriptor
  }
}