1.1.2 • Published 1 year ago

deru-event-emitter v1.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

event-emitter

global listening events (analogue - Vue event bus)

(best for async logic)

Installation

npm i deru-event-emitter --save

Methods

MethodDescription
subscribesubscribe to event
emitcalling event

Params

ProptypeDefaultDescription
onceBooleanfalsebind event once and remove after calling

How Usage?

Import Class with module

import EventEmitter from 'deru-event-emitter';

or require type

require EventEmitter = require('deru-event-emitter');

Use new instance of Class:

// main.js
export const emitter = new EventEmitter();

Example: async confirm modal actions

// component.js
import { emitter } from './main.js';

confirmAction() {
    return new Promise(resolve => {
        emitter.subscribe('confirm', res => {
            return resolve(res);
        })
    })
}

async openModal() {
    const confirm = await confirmAction();

    if (confirm) {
        // some logic
    }
}
// modal.js
import { emitter } from './main.js';

confirmModal() {
    emitter.emit('confirm', true);
}
1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago