New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@wide/emitter

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wide/emitter

Offer a simple yet useful way of communication between components

latest
Source
npmnpm
Version
2.1.1
Version published
Maintainers
4
Created
Source

Event Emitter

Offer a simple yet useful way of communication between components.

Install

npm install @wide/emitter --save

Listen events

import emitter from '@wide/emitter'

emitter.on('test', (a, b, c) => {})

or outside your script (without access to emitter)

document.onEvent('test', (1, 2, 3) => {})

##3 Listen event once only

import emitter from '@wide/emitter'

emitter.on('test', (a, b, c) => {}, { once: true })
// or
document.onEvent('test', (1, 2, 3) => {}, { once: true })

Emit events

import emitter from '@wide/emitter'

emitter.emit('test', 1, 2, 3)
// or
document.emitEvent('test', 1, 2, 3)

Unlisten event

import emitter from '@wide/emitter'

const ref = emitter.on('test', (a, b, c) => {})

emitter.off(ref)

Behind the scene

This emitter does not re-create an event dispatcher, but instead make use of document own event system, for exemple:

emitter.emit('test', 1, 2, 3)
// or
document.emitEvent('test', 1, 2, 3)

becomes:

document.dispatchEvent(new CustomEvent('@test', { detail: [1, 2, 3] }))

Authors

  • Aymeric Assier - github.com/myeti
  • Julien Martins Da Costa - github.com/jdacosta

License

This project is licensed under the MIT License - see the licence file for details

FAQs

Package last updated on 16 Jun 2021

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