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

Native node.js event emitter with generics for typescript

License

Notifications You must be signed in to change notification settings

imba-js/event-emitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();

About

Native node.js event emitter with generics for typescript

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published