Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Latest commit

 

History

History
54 lines (35 loc) · 1.19 KB

README.md

File metadata and controls

54 lines (35 loc) · 1.19 KB

Build Status

@imba/event-emitter

Native node.js event emitter with generics for typescript.

Installation

$ npm install --save @imba/event-emittter

or with yarn

$ yarn add @imba/event-emitter

Usage

Instead of extending the EventEmitter from node.js, create property for each event. It's similar in usage to what angular is doing with rxjs.

import {EventEmitter} from '@imba/event-emitter';

class MyClassWithEvents
{

    public onStart: EventEmitter<string> = new EventEmitter<string>();

    public onFinish: EventEmitter<string> = new EventEmitter<string>();


    public run(): void
    {
        this.onStart.emit('started');
        this.onFinish.emit('finished');
    }

}

const instance = new MyClassWithEvents;

instance.onStart.subscribe((msg) => {
    console.log(msg);    // output: started
});

instance.onFinish.subscribe((msg) => {
    console.log(msg);    // output: finished
});

instance.run();