JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3835
  • Score
    100M100P100Q123688F
  • License MIT

Event bus for your Javascript applications

Package Exports

  • js-event-bus

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (js-event-bus) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

js-event-bus

Simple Event Bus library built for any JavaScript application.

Installation

Using npm

npm i js-event-bus --save

Using yarn

yarn add js-event-bus

Usage

This library was built so you can use it in any JS application like Node.js apps, browser apps etc. The API is always the same.

Importing in Node.js application

If you want to use it in your Node.js apps you can import the library like this:

const eventBus = require('js-event-bus')();

Importing in browser application

If you want to use it in your Browser apps you can import the library like this:

<body>

  <div>Put your content here</div>

  <script src="/lib/js-event-bus/lib/js-event-bus.min.js"></script>
  <script>
    const eventBus = new EventBus();
  </script>
</body>

Api of the library

Register to an event

  eventBus.on('my-event', function () {
    console.log('Inside `my-event`');
  });

With this code, each time my-event is emited this function will be executed.

Register only one time to an event

  eventBus.once('my-event', function () {
    console.log('Inside `my-event`. It\'ll be executed only one time!');
  });

With this code, when my-event is emited this function will be executed. The next triggers of this event won't execute the callback because it is a one time event.

Register several time to an event

  eventBus.exactly(3, 'my-event', function () {
    console.log('Inside `my-event`. It\'ll be executed only 3 times!');
  });

With this code, when my-event is emited this function will be executed with a maximum of triggers of 3.

Detach an event

This feature is not yet implemented.

License

MIT