Dependency free pubsub model based library
const pubsub = require('pubsub-simplified-js');
const eventFun1 = data => console.log('do something with the data');
const eventFun2 = data => console.log('do something with the data here also');
const subscriber1st = pubsub.subscribe('eventName1', eventFun1);
const subscriber2nd = pubsub.subscribe('eventName1', eventFun2);
const subscriber3rd = pubsub.subscribe('eventName2', eventFun1);
pubsub.publish('eventName1', payloadRequiredByCallbackHere');
returns:
nothing
subscriber1st.unsubscribe();
returns:
nothing
pubsub.removeAll()
returns:
nothing
pubsub.remove('eventName1')
returns:
nothing
pubsubClass.detachFromAllEvents(eventFun1)
returns:
- true -> if such function is associated with any event and detached successfully
- false -> if no such function is associated with any event
pubsubClass.getSubscribers(eventName1)
returns:
- [] -> if no sch event is there (any event can't exist without <= 1 callback associated with it)
- [cb1, cb2, ......] -> all callbacks associated
pubsubClass.getSubscribersCount(eventName1)
returns:
number