adain-simple-event
v4.0.2
Published
Simple event dispatcher
Downloads
3
Readme
adain-simple-event
Install
npm install --save adain-simple-event
Usage
import SimpleEvent from "adain-simple-event";
const MY_EVENT_TYPE = 'MyEvent';
let callback = function(data){
console.log(data); // {msg: 'HI'}
};
let eventId = SimpleEvent.register(MY_EVENT_TYPE, callback);
SimpleEvent.dispatch(type, {msg: 'HI'});
// unregister
SimpleEvent.unRegister(eventId);
// register with context
eventId = SimpleEvent.register(MY_EVENT_TYPE, callback, this);
let eventIds = [];
eventIds.push(SimpleEvent.register(MY_EVENT_TYPE, callback));
eventIds.push(SimpleEvent.register(MY_EVENT_TYPE, callback));
eventIds.push(SimpleEvent.register(MY_EVENT_TYPE, callback));
// unregister with id array
SimpleEvent.unRegisterWithArr(eventIds);
eventIds = null;
// debug mode
SimpleEvent.isDebug = true;
// change warning count
SimpleEvent.warningCount = 10; // default is 5
License
MIT