Skip to main content

handler

npm istall @jelper/handler

Example

import { useSingleHandler, useMultipleHandler } from '@jelper/handler';

const single = useSingleHandler(); // new SingleHandler();
single.on(() => {
console.log('不执行');
});
single.on((data) => {
console.log(data)
});
single.call('single').then(() => ); // single
single.off();

const multiple = useMultipleHandler();
multiple.on(() => {
console.log('同步');
});
multiple.on(async (data) => {
console.log('异步', data);
});
multiple.call('multiple').then(() => {
console.log('end');
});
// 同步 异步multiple end

Api

通信调用工具, SingleHandler、MultipleHandler为了方便拓展,推荐使用 useSingleHandler、useMultipleHandler

SingleHandler

属性类型说明
on() => void-
off() => void-
call() => Promise-

MultipleHandler

属性类型说明
sizenumber绑定回调的数量
on() => void-
off(fn?: undefined) => void-
call() => PromisePromise.all 调用
callWithRace() => PromisePromise.race 调用

方法

方法参数返回值
useSingleHandlervoidSingleHandler
useMultipleHandlervoidMultipleHandler