Socket
Socket
Sign inDemoInstall

oj-eventaggregator

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    oj-eventaggregator

EventAggregator pattern. Use it in NodeJS and the browser.


Version published
Weekly downloads
6
increased by50%
Maintainers
1
Install size
10.3 kB
Created
Weekly downloads
 

Readme

Source

EventAggregator

Usage

import


import { EventAggregator } from "oj-eventaggregator";

create an instance


const ea = new EventAggregator<{
  "edit": boolean,
  "event": any,
  "another": any,
}>()

subscribe to an event

subscribers with "*" listen to all events


ea.on("edit", editing => element.classList.toggle("is-editing", editing))

ea.once("event", (data, event) => {})
ea.onMultiple(["event", "another"], (data, event) => {})
ea.onceMultiple(["event", "another"], (data, event) => {}) // callback will get called only once

emit an event


editBtn.addEventListener("click", e => ea.emit("edit", true))

ea.emitMultiple(["event", "another"], data)

unsubscribe a subscription


const sub = ea.on("event", (data, event) => {})
sub.off()

ea.clear("event") // removes all subscribers
ea.clearMultiple(["event", "another"])

pause / resume a subscription


const sub = ea.on("event", (data, event) => {})
sub.pause()
// sub does not respond to "event" emits
sub.resume()

ea.pause()
// eventaggregator does not emit any events
ea.resume()

Keywords

FAQs

Last updated on 12 Jan 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc