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

publisher-subscriber-pattern

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

publisher-subscriber-pattern

Publisher-subscriber pattern

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

About

  • Repository contains javascript implementation of publisher-subscriber pattern
  • dist/index.js returns Publisher class

Publisher

  • takes arguments: emitterInstance, addEventListener and removeEventListener
  • exposes methods: subscribe, unsubscribeAll and eventSubscribersCount
  • has property: subscribersCount

emitterInstance argument

  • object that will be bound to addEventListener and removeEventListener as this (see Function.prototype.bind)

addEventListener and removeEventListener arguments

  • methods exposed by emitterInstance which add and remove event listeners, respectively

subscribe method

  • requires two arguments: eventName and eventCallback
  • accepts optional argument: subscriberInstance that will be bound to eventCallback as this
  • subscribes eventCallback to eventName, so whenever event occurs the eventCallback is called (with subscriberInstance as this, if provided)

unsubscribeAll method

  • unsubscribes all eventCallbacks from all eventNames
  • runs removeEventListener of emitterInstance fro all eventNames

eventSubscriberCount method

  • requires argument: eventName
  • returns number of eventCallbacks subscribed to the evenName

subscribersCount method

  • returns number of eventCallbacks subscribed to all evenNames

Stack

  • typescript
  • jasmine, chai, sinon
  • babel
  • node (EventEmitter)

Description

  • I wanted to code library which I will be able to reuse in future projects

Keywords

FAQs

Package last updated on 06 Sep 2019

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