0.2.2 • Published 3 years ago

@solaldr/emitter v0.2.2

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

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