handler
- npm
- pnpm
- yarn
npm istall @jelper/handler
pnpm istall @jelper/handler
yarn 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
属性 | 类型 | 说明 |
---|---|---|
size | number | 绑定回调的数量 |
on | () => void | - |
off | (fn?: undefined) => void | - |
call | () => Promise | Promise.all 调用 |
callWithRace | () => Promise | Promise.race 调用 |
方法
方法 | 参数 | 返回值 |
---|---|---|
useSingleHandler | void | SingleHandler |
useMultipleHandler | void | MultipleHandler |