1.0.3 • Published 3 years ago

@locmod/event-aggregator v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

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)
1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago