Socket
Socket
Sign inDemoInstall

@jbeuckm/event-dispatcher

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @jbeuckm/event-dispatcher

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


Version published
Maintainers
1
Created

Readme

Source

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)

FAQs

Last updated on 18 Dec 2019

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