1.2.0 • Published 4 years ago
@legoleg/custom-event-bus v1.2.0
This is a basic event bus using window object to communicate with microfrontends
Simple usage
Global initialization
window.EventBus = new EventBus();Initialization in microfrontend/any place
export const AppEventBus = window.EventBus;Add topic
AppEventBus.addTopic('topic');Get all topics
export const AppTopics: ITopicEntity[] = AppEventBus.getAllTopics();Get current topic
export const EventTopic: ITopicEntity | undefined = AppEventBus.getTopic('topic');Listen event in current topic
EventTopic?.on('topic_event', (e: CustomEvent) => {
const anyDataFromEvent = e.detail;
console.log('any_action');
});Handle any event
EventTopic?.onAny((e: CustomEvent) => {
console.log('this is triggered on any topic event')
});Remove listening from topic
EventTopic?.delete('topic_event');Trigger event in topic
EventTopic?.emit('topic_event', {
any: 123,
field: '123',
here: true
});