Socket
Book a DemoInstallSign in
Socket

@locmod/event-aggregator

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@locmod/event-aggregator

This is very simple event aggregator

1.0.3
latest
npmnpm
Version published
Weekly downloads
131
87.14%
Maintainers
2
Weekly downloads
 
Created
Source

event-aggregator

This is very simple event aggregator

Installation

npm install --save @locmod/event-aggregator

Usage

Can be used directly

import { events } from '@locmod/event-aggregator'

or can be used as a class

const events = new EventAggregator()

Subscribe to event

useEffect(() => {
  const unsubscribe = events.subscribe('test event', console.log)

  return () => {
    unsubscribe()
  }
}, [])

or just

events.subscribe('test event', console.log)

Dispatch an event

events.subscribe('test event', { value: 10 }) // console.log will be called with { value: 10 }

Unsubscribe

events.unsubscribe('test event', console.log)

Get event

Get Event by name

events.getEvent('test event')
events.getEvent('unexistant event') // if event not found, it will be created and returned

Once

Subscribe to Event and unsubscribe after call

events.once('once in a lifetime', console.log)

Keywords

cache

FAQs

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.