eventcb

1.0.12 • Public • 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

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');		
};

FLOW

Package Sidebar

Install

npm i eventcb

Weekly Downloads

0

Version

1.0.12

License

ISC

Unpacked Size

2.66 kB

Total Files

3

Last publish

Collaborators

  • bobtxt