You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pk8f3pmu2/lib/emitter.js

20 lines
521 B

module.exports = {
setup(target) {
let listeners = [];
Object.assign(target, {
on(type, handle) {
if (typeof handle == 'function') {
listeners.push([type, handle]);
}
},
emit(type, ...params) {
listeners.forEach(([listenType, handle]) => type == listenType && handle(...params));
},
removeAllListeners() {
listeners = [];
}
});
}
}