Skip to content

SolalDR/emitter

Repository files navigation

Emitter

Maintainability npm bundle size (scoped) npm bundle size (scoped)

An abstract class to implement event system

DocumentationSource

How to install

With npm:

npm install @solaldr/emitter

With yarn:

yarn add @solaldr/emitter

How to use

A simple example to create a bus.

import Emitter from "emitter"

class ObjectEventable extends Emitter {
    constructor() {
        super();
        this.list = [];
    }

    add(item) {
        this.list.push(item);
        this.emit('add');
    }
}


var a = new ObjectEventable();
a.on('add', () => {
    console.log('Item added');
})

a.add('Test') // Should output 'Item added' in console 

A simple example to create a bus.

import Emitter from "emitter"

class Bus extends Emitter {
    constructor() {
        super();
    }
}

export default new Bus();

About

A js emitter disposed like an abstract class

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published