1.0.6 • Published 6 years ago

ban-duplicate v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

禁止重复的包装函数,使得被包装的异步函数能够在异步任务完成之后才能进行下一次调用

Params

banDuplicate(fn [, tipFn] [, timeout])

  • fn 不允许重复调用的函数
  • tipFn tipFn 前一个调用未结束,又重复操作调用对应的处理函数(例:可以提醒不要频繁操作)
  • timeout 超时,如果异步函数中没有手动调用任务结束后的回调函数next,超时后进行处理,默认3秒
Demo
import banDuplicate from 'ban-duplicate';

// fn (next is injected into the last position of the parameter)
function clickHandler = (e, otherParam, next) => {
    fetch({
        // config
    }).then((res) => {
        // deal response
    }).finally(() => {
        // calling the next function to make the next click event take effect.
        // if you don't call next, it will be enabled after 10 seconds
        next();
    });
}

// tipFn
function tipFunc = () => {
    alert('Do not operate frequently');
}

const wrapperedClickHandler = banDuplicate(clickHandler, tipFunc, 3000);

ReactDOM.render(
    <div>
        <button onClick={wrapperedClickHandler}>Click Me</button>
    </div>,
    document.getElementById('app');
);
1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago