From 1e61215b48e59e94c1ed98e4ef956227d689d6bc Mon Sep 17 00:00:00 2001 From: quanyawei <401863037@qq.com> Date: Mon, 06 Nov 2023 08:48:39 +0800 Subject: [PATCH] fix:小程序订阅消息 --- uni_modules/uview-ui/libs/function/debounce.js | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) diff --git a/uni_modules/uview-ui/libs/function/debounce.js b/uni_modules/uview-ui/libs/function/debounce.js new file mode 100644 index 0000000..ad3996b --- /dev/null +++ b/uni_modules/uview-ui/libs/function/debounce.js @@ -0,0 +1,29 @@ +let timeout = null + +/** + * ������������������������������������������������������������������wait������������������������ + * + * @param {Function} func ������������������������ + * @param {Number} wait ��������������� + * @param {Boolean} immediate ������������������ + * @return null + */ +function debounce(func, wait = 500, immediate = false) { + // ��������������� + if (timeout !== null) clearTimeout(timeout) + // ������������������������������������������ + if (immediate) { + const callNow = !timeout + timeout = setTimeout(() => { + timeout = null + }, wait) + if (callNow) typeof func === 'function' && func() + } else { + // ���������������������������������������������timeout������������������������������������wait���������������func������������ + timeout = setTimeout(() => { + typeof func === 'function' && func() + }, wait) + } +} + +export default debounce -- Gitblit v1.8.0