
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
light-event-bus
Advanced tools
light-event-bus.js is a lightweight event bus for Node.js and the browser.
This library can be used both with Node.js and the browser.
You can download the library here. For the browser there are 2 choiches:
light-event-bus.min.js
and import it in your app using the <script>
tag.npm install light-event-bus
or
yarn add light-event-bus
Or download light-event-bus.module.min.js
and import it using ES6 imports.
These two files are also delivered through a CDN at these addresses:
light-event-bus.min.js
: https://unpkg.com/light-event-bus@0.0.3-development/build/event-bus.min.jslight-event-bus.module.min.js
: https://unpkg.com/light-event-bus@0.0.3-development/build/event-bus.module.min.js<script src='../build/light-event-bus.min.js'></script>
<script>
const eventBus = new EVENT_BUS.EventBus()
const subscription = eventBus.subscribe('event', arg => console.log(arg))
eventBus.publish('event', 'message')
subscription.unsubscribe()
</script>
<script type='module'>
// if you are using npm/yarn
import { EventBus } from 'light-event-bus'
// if you have downloaded the file manually
import { EventBus } from '../build/light-event-bus.module.min.js'
const eventBus = new EventBus()
const subscription = eventBus.subscribe('event', arg => console.log(arg))
eventBus.publish('event', 'message')
subscription.unsubscribe()
</script>
Run
npm install light-event-bus
or
yarn add light-event-bus
const { EventBus } = require('light-event-bus')
const eventBus = new EventBus()
const subscription = eventBus.subscribe('event', arg => console.log(arg))
eventBus.publish('event', 'message')
subscription.unsubscribe()
The EventBus
constructor can be accessed through the main object exposed by this library.
If you are using Node.js:
const { EventBus } = require('light-event-bus')
If you are using ES6 imports:
import { EventBus } from 'light-event-bus'
If you are using <script>
:
const eventBus = new EVENT_BUS.EventBus()
Instances of EventBus
expose a subscribe
method.
Call subscribe
when you want to start listening for an event.
subscribe
takes two arguments: eventType
and callback
.
Example:
eventBus.subscribe('event', arg => console.log(arg))
eventType
can be an object of any type. Strings are recomended.callback
must be a function. This function can have 0 or 1 argument.subscribe
returns an object that exposes an unsubscribe
method.
Call unsubscribe
to cancel the current subscription.
Example:
const subscription = eventBus.subscribe('event', arg => console.log(arg))
// To cancel the subscription
subscription.unsubscribe()
Instances of EventBus
expose a publish
method.
Call publish
when you want to publish an event on the event bus.
publish
takes two arguments: eventType
and argument
.
Example:
eventBus.publish('event', 'message')
eventType
can be an object of any type. Strings are recomended.argument
is optional. It will be passed to all the listeners for the event. It can be of any type.In the case of this examples, only subscribers of the event 'event'
will be called, with the string 'mesage'
as argument.
Often a single instance of EventBus
is needed across an entire application, a singleton. The main object of this library already exposes a singleton, so that you don't have to create your own.
You can access the EventBusSingleton
in the following ways:
If you are using Node.js:
const { EventBusSingleton } = require('light-event-bus')
If you are using ES6 imports:
import { EventBusSingleton } from 'light-event-bus'
If you are using <script>
:
const eventBus = new EVENT_BUS.EventBusSingleton()
This singleton is just an instance of EventBus
, so it can be used as any other user-defined EventBus
.
FAQs
Lightweight event bus for node and the browser.
The npm package light-event-bus receives a total of 435 weekly downloads. As such, light-event-bus popularity was classified as not popular.
We found that light-event-bus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.