New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

event-boi

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-boi

A super-simple event bus

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
194
decreased by-31.93%
Maintainers
1
Weekly downloads
 
Created
Source

EventBoi

EventBoi is a super-simple, typesafe event bus.

It allows subscribing to pre-defined events and their associated payloads.

Installation

npm install event-boi
yarn add event-boi

Usage

event-boi is designed to be used with TypeScript (although there's nothing stopping you from using it in plain JavaScript). The possible events should be declared when creating an event bus instance. The TS compiler will then ensure that only events that exist can be published and subscribed to and that the payloads for each event is correct.

import createEventBus from "event-boi";

// if using TypeScript you must pre-define the events and their payloads.
interface Events {
  game_played: { result: "win" | "loss" };
  message_sent: string;
}

const MyEventBus = createEventBus<Events>();

const unsubscribe = MyEventBus.subscribe("message_sent", (message) => {
  console.log(`A message was sent with the content "${message}"`);
});

// later...

MyEventBus.publish("message_sent", "Hello, world");
// logs: A message was sent with the content "Hello, world"

// to unsubscribe just call the `unsubscribe` function returned from the `subscribe` method:
unsubscribe();

Keywords

FAQs

Package last updated on 24 Aug 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc