New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@untemps/event-dispatcher

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@untemps/event-dispatcher

Abstract EventDispatcher class

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-77.78%
Maintainers
1
Weekly downloads
 
Created
Source

@untemps/event-dispatcher

Abstract class that allows to internally dispatch events and attach subscribers to listen for them.

.github/workflows/index.yml

Installation

yarn add @untemps/event-dispatcher

Usage

Import EventDispatcher:

import { EventDispatcher } from '@untemps/event-dispatcher'

Create a class that extends EventDispatcher:

class Foo extends EventDispatcher {
	constructor() {
		super()
	}

	foo() {
		this.dispatchEvent(new Event('foo', { bubbles: false, cancelable: false, composed: false }))
	}
}

Each instance can now attach a subscriber to listen for events:

const onFoo = (event) => console.log('foo has be triggered!')
const myFoo = new Foo()
myFoo.addEventListener('foo', onFoo)

And detach it:

myFoo.removeEventListener('foo', onFoo)

All subscriptions for a specific event type can be detached in batches:

const myFoo = new Foo()
myFoo.addEventListener('foo', onFoo1)
myFoo.addEventListener('foo', onFoo2)
myFoo.clearType('somethingDone')

All instance subscriptions can be detached in batches:

const myFoo = new Foo()
myFoo.addEventListener('foo', onFoo)
myFoo.addEventListener('bar', onBar)
myFoo.cleanup()

Todos

  • Add examples
  • Rewrite with TypeScript

Keywords

FAQs

Package last updated on 24 Jun 2020

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

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc