Socket
Book a DemoInstallSign in
Socket

deru-event-emitter

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deru-event-emitter

global listening events (analogue - Vue event bus)

1.1.2
latest
npmnpm
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 07 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.