emit-events
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

Emit Events

A simple event library for Javascript

Installation

npm i emit-events --save
yarn add emit-events

Usage

import Events from 'emit-events';
 
// emit
Events.emit('myEvent', { foo: 'bar' });
 
// subscribe
Events.subscribe('myEvent', payload => {
  // do something
});

Decorator Usage

import { emit, subscribe } from 'emit-events';
 
@subscribe('onEvent')
@emit()
class Foo {
  onEvent(payload) {
    console.log(payload);
  }
 
  sendIt() {
    this.emit('onEvent', { foo: 'bar' });
  }
}

Can also subscribe to multiple events

import { emit, subscribe } from 'emit-events';
 
@subscribe(['onEvent', 'onEventAgain'])
@emit()
class Foo {
  onEvent(payload) {
    console.log(payload);
  }
 
  onEventAgain(payload) {
    console.log(payload);
  }
 
  sendIt() {
    this.emit('onEvent', { foo: 'bar' });
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i emit-events

Weekly Downloads

7

Version

0.1.4

License

ISC

Unpacked Size

6.79 kB

Total Files

11

Last publish

Collaborators

  • jadenlemmon