1.2.7 • Published 6 years ago

ez-channel v1.2.7

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
6 years ago

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 = require('ez-channel');

web

  import {Channel} from 'ez-channel';

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.create("myAwesomeChannel");

subscribe

Subscribe gives you all the functions that you need to trigger and listen for events. See example below.

  const channel = Channel.subscribe();

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.on("myAwesomeChannel", "youAreAwesome", function() {
      console.log("someone says your are awesome");
    });

dispatch event

If you want to dispatch an events, just simple do it like follow.

  channel.send("myAwesomeChannel", "youAreAwesome");

dispatch and listen with data

Of course it is possible the send and receive data by "on" and "send". See example below:

  channel.send("myAwesomeChannel", "youAreAwesome",{isAwesome: true});
  channel.on("myAwesomeChannel", "youAreAwesome", function(obj) {
      if(obj.isAwesome) {
        console.log("you are awesome");
      }
    });

remove channel

Maybe it make sometimes sense to remove a channel. You can do it like follow.

  channel.remove("myAwesomeChannel");

Licence

Apache 2.0

Happy using and keep coding =)

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago