1.0.5 • Published 6 years ago

@jbeuckm/event-dispatcher v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

EventDispatcher

Regular old EventDispatcher pattern with set of types fixed in the constructor.

Build Status

Installation

yarn add @jbeuckm/event-dispatcher

Usage

import EventDispatcher from '@jbeuckm/EventDispatcher'

class MyDispatcher extends EventDispatcher {
	constructor() {
		super([MY_EVENT_TYPE, MY_OTHER_EVENT_TYPE])
	}

	runAndTellThat = action => {
		this.dispatchEvent(MY_EVENT_TYPE, action.data)
	}
}

Consume events...

import MyDispatcher from './MyDispatcher'

const thing = new MyDispatcher()

const handler = (event) => {
	console.log(`Received a "${event.type}" event...`, event)
}

thing.addEventListener(MY_EVENT_TYPE, handler)

Clean up...

thing.removeEventListener(MY_EVENT_TYPE, handler)
1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.0

7 years ago