1.0.5 • Published 4 years ago

@markdomkan/js-events v1.0.5

Weekly downloads
6
License
ISC
Repository
github
Last release
4 years ago

JsEvents

Usage

const JsEvents = require('@markdomkan/js-events');

or ES6 & TS

import JsEvents from '@markdomkan/js-events';

You can extend a class with JsEvents

class MyClass extends JsEvents{
    constructor(){
        this.on('myCustomEvent', name => console.log(name));
    }

    triggerMyCustomEvent(){
        this.emit('myCustomEvent','Hello World');
    }
}

or use as Object. Also can pass an object to class constructor to inject the methods on the object.

customObject = new JsEvents(customObject);
customObject.on('myCustomEvent', name => console.log(name));
customObject.emit('myCustomEvent','Hello World');

Avaiable Methods

Subscribe new event

on(eventName, callbackFunction): this;

Emit event with optional object data

emit(eventName: string, data?: any): this; 

Unsubscribe event

delete(eventName: string): this; 

Get all subcrited event names

emitters(): string[]; 

Get all callbacks by event name

listeners(eventName: string): (data: any) => void; 

Check if exist passed event

hasListeners(eventName: string): boolean; 
1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago