1.0.5 • Published 5 years ago

@antyper/simple-event-bus v1.0.5

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
5 years ago

Simple Event Bus

This package help you emit events and handle it in one place. Whole project is written in TypeScript and RxJs.

Library is compatible with Inversify. You can initialize your EventBus in IOC container.

Example with Inversify
import {EventBus} from "./EventBus";
import {Container} from "inversify";

export const getContainer: () => Container = () => {
    const container: Container = new Container();

    container.bind<TestEventListener>('TestEventListener')
        .to(TestEventListener)
        .inRequestScope();
    
    container.bind<EventBus>('EventBus')
        .toDynamicValue((context) => {
            const eventBus: EventBus = new EventBus();
    
            eventBus.addEvent(TestEvent);
            eventBus.addEventListener(
                TestEvent,
                context.container.get('TestEventListener'),
            );
    
            return eventBus;
        })
        .inRequestScope();
}

const container: Container = getContainer();

const eventBus: EventBus = container.get<EventBus>('EventBus');
// Events are here handled 
eventBus.handle();

const testEvent: TestEvent = new TestEvent();
// Here is your event emitted
eventBus.emitEvent(testEvent);

Simple First Example

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago