New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 - npm Package Compare versions

Comparing version 2.0.3 to 2.1.0

dist/SimpleSignal.js

47

package.json
{
"name": "simplesignal",
"version": "2.0.3",
"version": "2.1.0",
"description": "Super-simple signals class",
"main": "dist/es5/SimpleSignal.js",
"main": "dist/simplesignal.js",
"scripts": {
"tsc": "tsc --pretty",
"test": "node tests/test",
"build": "webpack",
"coverage": "nyc npm test",
"test": "mocha test/.setup.js test/**/*-test-*.js",
"test:watch": "mocha -w test/.setup.js test/**/*-test-*.js",
"lint": "tslint -c tslint.json src/*.ts",
"build": "npm run lint && npm run tsc"
"prepublish": "webpack --debug; webpack -p"
},

@@ -24,3 +26,3 @@ "repository": {

"tiny",
"typescript"
"typescript"
],

@@ -34,6 +36,33 @@ "author": "Zeh Fernando <npm@zehfernando.com> http://zehfernando.com",

"devDependencies": {
"tape": "^4.5.1",
"tslint": "^3.3.0",
"typescript": "^1.8.9"
"ava": "^0.16.0",
"babel": "^6.5.2",
"babel-core": "^6.18.2",
"babel-loader": "^6.2.7",
"babel-plugin-external-helpers": "^6.8.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-2": "^6.18.0",
"chai": "^3.5.0",
"change-case": "^3.0.0",
"core-js": "^2.4.1",
"coveralls": "^2.11.11",
"cross-env": "^3.1.3",
"mocha": "^3.1.2",
"nyc": "^9.0.1",
"rimraf": "^2.5.3",
"rollup": "^0.36.3",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-commonjs": "^5.0.5",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-sourcemaps": "^0.4.0",
"ts-loader": "^1.2.1",
"tslint": "^3.13.0",
"tslint-loader": "^2.1.5",
"typescript": "^2.0.10",
"webpack": "^1.13.3"
},
"babel": {
"presets": [
"es2015"
]
}
}

@@ -5,4 +5,9 @@ # Simple Signal

Signals are like *Events*, *Delegates*, or *Callbacks* on other languages or platforms. You can create a signal that other parts of the code can "listen" to. When that signal is *dispatched*, all listeners are called with the passed parameters.
SimpleSignal is created with TypeScript, but aimed to be used as a standard JavaScript library.
## Install
```

@@ -14,3 +19,3 @@ $ npm install simplesignal

You create signals that other classes subscribe to. Example:
First, import your signal:

@@ -21,20 +26,31 @@ ```

// Include (JavaScript ES6) (Test!)
import * as SimpleSignal from 'simplesignal';
// Include (JavaScript ES6)
import SimpleSignal from 'simplesignal';
// Include (TypeScript)
import SimpleSignal from 'simplesignal';
```
// Declare, inside MyClass
Then, you can create a signal. For example, inside a class:
```
public onSomethingHappened = new SimpleSignal();
```
// Subscribe, outside MyClass
Then other parts of the code can subscribe (listen) to that signal:
```
myClassObject.onSomethingHappened.add(function(id) {
console.log("Something happened with id" + id
console.log("Something happened with an id of " + id
});
```
// Dispatch, inside MyClass
Signals can then be dispatched with parameters:
```
onSomethingHappened.dispatch("some-id");
```
This will call all subscribed functions with the given parameter.
## Full reference (JS)

@@ -49,2 +65,6 @@

// Anonymous functions are, of course, fine
onSomethingHappened.add(function() { ... });
onSomethingHappened.add(() => { ... });
// Unsubscribe

@@ -61,2 +81,24 @@ onSomethingHappened.remove(myFunc);

onSomethingHappened.dispatch(...args)
```
## Additional TypeScript reference
If your project already uses TypeScript, it has the advantage of using SimpleSignal's definition files for strict typing.
In this case, one can use a generic interface to enforce the correct dispatch/listener parameters:
```
// Create, with a given interface as a Generic
onSomethingHappened = new SimpleSignal<(action:string) => void>();
// The listeners must fulfill the interface
function myFunc(action:string) {
console.log(action);
}
// Subscribe
onSomethingHappened.add(myFunc);
// Dispatch must also respect the interface
onSomethingHappened.dispatch("some-action")
```
dist/es5/SimpleSignal.js
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