communication-bus
Version:
Publisher subscriber library for communication in JS across components
33 lines (26 loc) • 935 B
JavaScript
import EventSchemaMap from "./schema"
const register = (eventName, schema)=>{
if(!eventName) throw new Error("Event name is required");
if(EventSchemaMap[eventName]) throw new Error("Event name is already exist");
EventSchemaMap[eventName] = schema;
return true;
}
const deregister = (eventName)=>{
if(!eventName) throw new Error("Event name is required");
if(!EventSchemaMap[eventName]) throw new Error(`Event with ${eventName} doesn't exist`);
delete EventSchemaMap[eventName];
}
const getSupportedEventList = ()=>{
return Object.keys(EventSchemaMap);
}
const getSchemaByEventName = (eventName)=>{
if(!eventName) throw new Error("Event name is required");
if(!EventSchemaMap[eventName]) throw new Error(`Event with ${eventName} doesn't exist`);
return EventSchemaMap[eventName]
}
export default {
register,
deregister,
getSchemaByEventName,
getSupportedEventList,
}