super-pub-sub.js is a ligtweight、none dependence lib, it supports event pulish、subscibe and offline subscibe.
🏠 Homepage
npm i @theshy/pub-sub.js --save
<script src="/dist/pub-sub.js"></script>
var e = new eventBus({
});
const handler = (params) => {
console.log(params)
}
//event subscripte
e.on('msg', handler);
//event distribute
e.emit('msg', 'recive a message');
//remove subscripte
e.off('msg', handler)
const _event = require('@theshy/pub-sub.js')
const e = new _event({}) //init
const handler = (params) => {
console.log(params)
}
//event subscripte
e.on('msg', handler);
//event distribute
e.emit('msg', 'recive a message');
//remove subscripte
e.off('msg', handler)
add handler functon
name | type | default | descriptin |
---|---|---|---|
type | String Number Boolean Expression | - | subject of pub-sub |
cb | Function | - | handler of pub-sub |
offline | Boolean | false | support offline subscibe? default:false. |
flag | Boolean | false | unshift or push handler in event queue(true: unshift, false: push) |
add handler functon, this function will only execute one time
name | type | default | descriptin |
---|---|---|---|
type | String Number Boolean Expression | - | subject of pub-sub |
cb | Function | - | handler of pub-sub |
offline | Boolean | false | support offline subscibe? default:false. |
flag | Boolean | false | unshift or push handler in event queue(true: unshift, false: push) |
ps: the handler use once() to add will not be removed by off()
publish a messgae in a subject
name | type | default | descriptin |
---|---|---|---|
type | String Number Boolean Expression | - | subject of publish |
cb | Function | - | message of publish |
remove hanbler function
ps: off(type) will remove all handler under this subject
return all pulish message list
return all subscibe handler
npm run test
👤 theShy
- Github: @theShy
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!