import Register from 'wing-register';
const register = new Register();
const fn1 = () => console.log('fn1 called');
const fn2 = () => console.log('fn2 called');
register.register(fn1);
register.register(fn2);
register.register(fn2);
/* ****************************** */
register.excute();
/**
* will output:
*
* fn1 called
* fn2 called
*/
/* ****************************** */
register.unregister(fn1);
register.excute();
/**
* will output:
*
* fn2 called
*/
/* ****************************** */
register.clear();
register.excute();
/**
* nothing will output
*/
import Register from 'wing-register';
interface Device {
id: string;
}
type CallBack = (d: Device) => void;
const register = new Register<CallBack, Device>();
const fn = (v: Device) => console.log('---', v.id);
register.register((v) => console.log('+++', v.id));
register.register((v) => console.log('+++', v.id));
register.register(fn);
register.register(fn);
register.register(fn);
setInterval(() => {
const id = `${Math.random()}`;
register.excute({ id });
}, 1000);
setTimeout(() => {
register.unregister(fn);
}, 2000);
setTimeout(() => {
register.clear();
}, 5000);