ps 0.0.1
Install from the command line:
Learn more about npm packages
$ npm install @anh-ld/ps@0.0.1
Install via package.json:
"@anh-ld/ps": "0.0.1"
About this version
- Pub/Sub JS library that's inspirated from mitt.
- The project's goal is to practice building the pub/sub library from scratch.
Add .npmrc
into project
@culee:registry=https://npm.pkg.github.com
npm install @culee/ps
import pubsub from './src'
const ps = pubsub()
const foo1 = e => console.log('foo1', e)
const foo2 = e => console.log('foo2', e)
const bar = e => console.log('bar', e)
const wildcard = e => console.log('*', e)
/* register event listener */
ps.on('foo', foo1);
ps.on('foo', foo2);
ps.on('bar', bar)
/* register wildcard event listener */
ps.on('*', wildcard)
/* fire an event */
ps.emit('foo', { a: 'b' })
ps.emit('bar')
/* clear specific event listener */
ps.off('foo', foo1)
/* clear all event listeners of specific event name */
ps.clear('foo')
/* clear all event listeners */
ps.clear()