Lightweight library to create custom events and trigger and subscribe them from everywhere. Works standalone or with other frameworks like react.js or vue.js
What can this program do ?
Sometimes you need a simple implementation to create global channels and subscribe them from other pieces of code, components or stuff like that. With ez-channel it is easy ;-)
Benefit
If you want to define, trigger and process events in different files, this library can help you. You only need to include ez-channel in your files where you want to work with your custom events.
Installation
Package is available here: https://www.npmjs.com/package/ez-channel
npm i ez-channel
Usage
Just include it into your web or server project
node
const Channel = ;
web
;
or you can include the transpiled script from dist folder.
create channel
A channel is that object that manage all events and subscriptions for you. To create a new channel, just do it like follow.
Channel;
subscribe
Subscribe gives you all the functions that you need to trigger and listen for events. See example below.
const channel = Channel;
create and listen to event
If you want to create an event, uhm let´s say "youAreAwesome" and you want listen to that, just do it like follow.
channel;
dispatch event
If you want to dispatch an events, just simple do it like follow.
channel;
dispatch and listen with data
Of course it is possible the send and receive data by "on" and "send". See example below:
channel;
channel;
remove channel
Maybe it make sometimes sense to remove a channel. You can do it like follow.
channel;
Licence
Apache 2.0
Happy using and keep coding =)