react-native-drawing
Version:
A React Native library that provides a canvas to perform drawing actions
31 lines (30 loc) • 812 B
JavaScript
/**
* Abstract class with the base infraestructure to manage Message Events
*/
export class MessageEventDispatcher {
constructor() {
Object.defineProperty(this, "messageEventIndex", {
enumerable: true,
configurable: true,
writable: true,
value: {}
});
}
/**
* Launch events with the specified target
* @param arg - data to be received by the event
*/
async dispatchMessage(target, arg) {
const handle = this.messageEventIndex[target];
if (handle === undefined) {
return;
}
return handle(arg);
}
/**
* Save handlers in the event index (for the specific target)
*/
onMessage(target, callback) {
this.messageEventIndex[target] = callback;
}
}