New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

events-system

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

events-system

Event System

latest
Source
npmnpm
Version
0.0.9
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

Event System

Event System used for handling events between components

npm GitHub

Event System is a package used for handling different events between parts of code written in Typescript.

EventsSystem

new EventSystem(options: EventsSystemOptions)

Initializes the Event System class.

Parameters:

  • options
    • bufferDirection {"FIFO" | "LIFO"} - The direction of the events buffer. Defaults to "FIFO".
    • bufferSize {number} - The size of the buffer.

Example:

// Initialization without options
const eventSystem = new EventSystem(); // OK ✅

// Initialization with options
const eventSystem = new EventSystem({
  bufferDirection: "LIFO",
  bufferSize: 10
}); // OK ✅

subscribe(event, handler)

Subscribes handler to be called when the event is triggered.

Parameters:

  • event {keyof E} The event name.
  • handler {Function} The handler function.

Example:

type MyEvents = {
  "event": () => void;
}

const eventSystem = new EventSystem<MyEvents>();

// Subscribe to event
eventSystem.subscribe("event", () => {
  // Do something
});

unsubscribe(event, handler)

Unsubscribes the handler from the event.

Parameters:

  • event {keyof E} The event name.
  • handler {Function} The handler function.

Example:

type MyEvents = {
  "event": () => void;
}

const eventSystem = new EventSystem<MyEvents>();

// Subscribe to event
eventSystem.subscribe("event", () => {
  // Do something
});

// Unsubscribe from event
eventSystem.unsubscribe("event", () => {
  // Do something
});

notify(event, ...args)

Triggers the event with the given arguments.

Parameters:

  • event {keyof E} The event name.
  • args {Parameters<E[keyof E]>} The arguments to pass to the handler.

Example:

type MyEvents = {
  "event": (a: number, b: string) => void;
}

const eventSystem = new EventSystem<MyEvents>();

// Subscribe to event
eventSystem.subscribe("event", (a, b) => {
  // Do something
});

// Trigger event
eventSystem.notify("event", 1, "Hello");

Keywords

typescript

FAQs

Package last updated on 04 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