Skip to content

throttle/debounce

对函数进行节流/防抖

@ifanrx/uni-mp 内置的 throttle 和 debounce 方法与 lodash 一致,区别是内置的 throttle 和 debounce 还会在返回的函数对象下加多一个 pending 方法,用于判断当前函数是否处于运行中状态

js
import {debounce} from '@ifanrx/uni-mp'

const debounced = debounce(() => console.log('hello world'), 3000)

console.log(debounced.pending()) // false

debounced()

console.log(debounced.pending()) // true

具体使用方法参考 lodash 官方文档

throttle

debounce