@e.fe/emitter
v1.0.2
Published
自定义事件封装
Downloads
2
Readme
@e.fe/emitter
event emitter
Usage
import Emitter from '@e.fe/emitter';
const emitter = new Emitter();
function callback(msg) {
console.log('msg: ', msg);
}
// bind event
emitter.on('event-name', callback);
// bind event, only emit once
emitter.once('event-name', callback);
// emit event
emitter.emit('event-name', 'hello world');
// unbind event, only specified function
emitter.off('event-name', callback);
// unbind event, all functions
emitter.off('event-name');