1.2.0 • Published 3 years ago

@legoleg/custom-event-bus v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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
  });
1.2.0

3 years ago

1.1.1

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago