Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simplesignal

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplesignal

Super-simple signals class

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
27K
increased by10.31%
Maintainers
1
Weekly downloads
 
Created
Source

Simple Signal

This is a super-simple signals class inspired by Robert Penner's AS3Signals.

Install

$ npm install simplesignal

Usage

You create signals that other classes subscribe to. Example:

// Include (JavaScript ES5)
var SimpleSignal = require('simplesignal').default;

// Include (JavaScript ES6, TypeScript)
import SimpleSignal from 'simplesignal';

// Declare, inside MyClass
public onSomethingHappened = new SimpleSignal();

// Subscribe, outside MyClass
myClassObject.onSomethingHappened.add(function(id) {
	console.log("Something happened with id" + id
});

// Dispatch, inside MyClass
onSomethingHappened.dispatch("some-id");

Full reference (JS)

// Create
onSomethingHappened = new SimpleSignal();

// Subscribe
onSomethingHappened.add(myFunc);

// Unsubscribe
onSomethingHappened.remove(myFunc);

// Clear subscribers
onSomethingHappened.removeAll();

// Number of subscribers
console.log(onSomethingHappened.numItems);

// Dispatch
onSomethingHappened.dispatch(...args)

Keywords

FAQs

Package last updated on 21 May 2016

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