eventcb
v1.0.12
Published
One trigger can invoke all the subscribed callbacks events, Can create any number of triggers and each trigger can have any number of event subscribers
Downloads
17
Maintainers
Readme
One trigger can invoke all the subscribed callbacks events
Can create any number of triggers and each trigger can have any number of event subscribers
Ultra-light code, ~400 bytes and 15 lines of code
Subscribing to the events
Events.bind('eventname', myFunction);
Triggering the subscribed events
Events.trigger('eventname');
ReactJS EXAMPLE
TRIGGER FROM COMPONENT A
import Events from 'eventcb';
<button onClick={()=> Events.trigger('MYDATA-CHANGED') }>Modify</button>
<button onClick={()=> Events.trigger('MYDATA-DELETED') }>Delete</button>
RECEIVED AT COMPONENT B
import Events from 'eventcb';
componentDidMount =()=> {
Events.bind('MYDATA-CHANGED', this.someActionOnChange);
Events.bind('MYDATA-DELETED', this.someCleanupOnDelete);
};
RECEIVED AT COMPONENT C
import Events from 'eventcb';
componentDidMount =()=> {
Events.bind('DATACHANGED', this.someMoreActionOnChange);
};
REMOVE BINDING
import Events from 'eventcb';
componentWillUnmount() {
Events.unbind('MYDATA-CHANGED');
};