smart-table-events

tiny event emitter/listener

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
smart-table-events
1.0.104 years ago6 years agoMinified + gzip package size for smart-table-events in KB

Readme

smart-table-events
CircleCI
Tiny event emitter/event listener for nodejs and browsers.

Installation

npm

`npm install --save smart-table-events`

yarn

`yarn add smart-table-events`

Usage

Event emitter

import {emitter} from 'smart-table-events';

const em = emitter();

//a listener function 
const listener = (...args) => console.log(args);

//register to an event
em.on('MY_EVENT',listener);

//dispatch event
em.dispatch('MY_EVENT','foo','bar');
// > ['foo','bar']

//unsubscribe
em.off()// all listeners of all events;
em.off('MY_EVENT')// all listeners of event "MY_EVENT")
em.off('MY_EVENT', listener)// remove a particular listener

Proxy listener

Create convenient/meaningful methods to register events.
import {emitter, proxyListener} from 'smart-table-events';

const em = emitter();
const proxyFactory = proxyListener({MY_EVENT:'myMethod'});
const instance = proxyFactory({emitter:em);

const listener = (...args) => console.log(args);

//register with convenient method
instance.myMethod(listener);

em.dispatch('MY_EVENT','foo','bar');
// > ['foo','bar']

//unsubscribe
instance.off('MY_EVENT') //unregister all listeners to MY_EVENT held by the proxy instance
instance.off() //unregister all listeners held by the proxy instance

Contribute

test

npm

`npm test`

yarn

`yarn test`

Issues

Bugs only please (or feature request to be discussed), must come with running example