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

1.0.10 • Public • Published

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

Package Sidebar

Install

npm i smart-table-events

Weekly Downloads

124

Version

1.0.10

License

MIT

Unpacked Size

21 kB

Total Files

11

Last publish

Collaborators

  • lorenzofox3