mini-signals
Advanced tools
Comparing version 1.2.0 to 2.0.0-0
{ | ||
"name": "mini-signals", | ||
"version": "1.2.0", | ||
"description": "signals, in JavaScript, fast", | ||
"main": "lib/mini-signals.js", | ||
"jsnext:main": "src/mini-signals.js", | ||
"types": "typings/mini-signals.d.ts", | ||
"version": "2.0.0-0", | ||
"description": "signals, in TypeScript, fast", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"/dist" | ||
], | ||
"scripts": { | ||
"test": "npm run mocha", | ||
"test:fast": "mocha --compilers js:babel/register ./test/mini-signals-spec.js", | ||
"test": "npm-run-all test:*", | ||
"test:unit": "mocha --reporter spec --compilers ts:ts-node/register src/**/*.spec.ts", | ||
"test:deopt": "node --trace_opt --trace_deopt ./bench/test-deopt.js | grep \"disabled optimization\" || true", | ||
"lint": "semistandard src/*.js test/*.js", | ||
"check": "npm run lint", | ||
"build": "npm run rollup && npm run browserify && npm run uglify && npm run jsdoc2md", | ||
"rollup": "rollup ./src/index.js | babel -o ./lib/mini-signals.js --no-comments", | ||
"browserify": "browserify ./lib/mini-signals.js -o browser.js -s MiniSignal", | ||
"uglify": "uglifyjs browser.js -o browser.min.js", | ||
"build": "npm-run-all build:*", | ||
"build:tsc": "tsc", | ||
"xxx-build:jsdoc2md": "jsdoc-parse ./src/mini-signals.ts | dmd > API.md", | ||
"coverage": "istanbul cover -- ./node_modules/mocha/bin/_mocha --compilers js:babel/register ./test/mini-signals-*.js", | ||
"mocha": "mocha --compilers js:babel/register", | ||
"bench": "babel-node ./bench/emit.js && babel-node ./bench/emit-context.js", | ||
"_prepublish": "npm run build && npm test", | ||
"jsdoc2md": "jsdoc-parse ./src/mini-signals.js | dmd > API.md", | ||
"bench": "ts-node ./bench/index.js | tee ./bench/latest.md", | ||
"bench:emit": "ts-node ./bench/emit.js", | ||
"bench:emit-bind": "ts-node ./bench/emit-bind.js", | ||
"bench:emit-context": "ts-node ./bench/emit-context.js", | ||
"bench:emit-depot": "ts-node ./bench/emit-depot.js", | ||
"version": "chg release -y && git add -A CHANGELOG.md", | ||
"np": "npm run build && np" | ||
"np": "npm run build && np --tag next --any-branch", | ||
"fix": "npm-run-all fix:*", | ||
"fix:prettier": "prettier --write './{src, bench}/**/*.*'", | ||
"fix:lint": "eslint './{src, bench}/**/*.*' --fix" | ||
}, | ||
@@ -42,7 +45,15 @@ "repository": { | ||
"devDependencies": { | ||
"assume": "^1.4.1", | ||
"babel": "^5.8.23", | ||
"@types/chai": "^4.3.4", | ||
"@types/mocha": "^10.0.1", | ||
"@typescript-eslint/eslint-plugin": "^5.56.0", | ||
"benchmark": "^1.0.0", | ||
"browserify": "^11.2.0", | ||
"chai": "^4.3.7", | ||
"chg": "^0.4.0", | ||
"dmd": "^1.2.0", | ||
"eslint": "^8.36.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-config-standard-with-typescript": "^34.0.1", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-n": "^15.6.1", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"eventemitter3": "^1.1.1", | ||
@@ -52,8 +63,9 @@ "istanbul": "^0.3.19", | ||
"mocha": "^2.2.5", | ||
"np": "^2.16.0", | ||
"rollup": "^0.16.4", | ||
"semistandard": "^7.0.5", | ||
"np": "^2.20.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "2.8.7", | ||
"signals": "^1.0.0", | ||
"uglifyjs": "^2.4.10" | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.0.2" | ||
} | ||
} |
# mini-signals | ||
signals, in JavaScript, fast | ||
[![NPM](https://img.shields.io/npm/v/mini-signals.svg)](https://www.npmjs.com/package/mini-signals) [![Build Status](https://travis-ci.org/Hypercubed/mini-signals.svg)](https://travis-ci.org/Hypercubed/mini-signals/) [![Codacy Badge](https://api.codacy.com/project/badge/18fa3fdfb90b43c7966f817124307d66)](https://www.codacy.com/app/hypercubed/mini-signals) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Hypercubed/mini-signals/blob/master/LICENSE) | ||
[![NPM](https://img.shields.io/npm/v/mini-signals.svg)](https://www.npmjs.com/package/mini-signals) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Hypercubed/mini-signals/blob/master/LICENSE) | ||
## Description | ||
Custom event/messaging system for JavaScript inspired by [js-signals](https://github.com/millermedeiros/js-signals) originally based on [EventEmitter3](https://github.com/primus/eventemitter3) code base. | ||
Custom event/messaging system for TypeScript/JavaScript inspired by [js-signals](https://github.com/millermedeiros/js-signals) originally based on [EventEmitter3](https://github.com/primus/eventemitter3) code base. | ||
There are several advantages to signals over event-emitters (see [Comparison between different Observer Pattern implementations](https://github.com/millermedeiros/js-signals/wiki/Comparison-between-different-Observer-Pattern-implementations)). However, the current implementation of [js-signals](https://github.com/millermedeiros/js-signals) is (arguably) slow compared to other implementations (see [EventsSpeedTests](https://github.com/Hypercubed/EventsSpeedTests)). `mini-signals` is a fast, minimal emitter, with an API similar to [js-signals](https://github.com/millermedeiros/js-signals). | ||
There are several advantages to signals over event-emitters (see [Comparison between different Observer Pattern implementations](https://github.com/millermedeiros/js-signals/wiki/Comparison-between-different-Observer-Pattern-implementations)). However, the current implementation of [js-signals](https://github.com/millermedeiros/js-signals) is (arguably) slow compared to other implementations (see [EventsSpeedTests](https://github.com/Hypercubed/EventsSpeedTests)). `mini-signals` is a fast, minimal emitter, with an API similar to [js-signals](https://github.com/millermedeiros/js-signals). | ||
> Note: Signals here are the type defined by [js-signals](https://github.com/millermedeiros/js-signals) inspired by AS3-Signals. They should not to be confused with [SolidJS](https://www.solidjs.com/tutorial/introduction_signals) or Angular signals. | ||
## Install | ||
@@ -16,33 +19,21 @@ | ||
``` | ||
```sh | ||
npm install mini-signals | ||
``` | ||
### jspm: | ||
## Example Usage | ||
``` | ||
jspm install mini-signals=npm:mini-signals | ||
``` | ||
```ts | ||
import { MiniSignal } from "mini-signals"; | ||
### bower: | ||
const mySignal = new MiniSignal<[string, string]>(); | ||
``` | ||
bower install mini-signals | ||
``` | ||
const binding = mySignal.add(onSignal); //add listener | ||
## Example Usage | ||
mySignal.dispatch("foo", "bar"); // dispatch signal passing custom parameters | ||
binding.detach(); // remove a single listener | ||
***When not using a module loader the mini-signals constructor (`MiniSignal`) is global.*** | ||
``` | ||
var MiniSignal = require('mini-signals'); | ||
var mySignal = new MiniSignal(); | ||
var binding = mySignal.add(onSignal); //add listener | ||
mySignal.dispatch('foo', 'bar'); //dispatch signal passing custom parameters | ||
binding.detach(); //remove a single listener | ||
function onSignal(foo, bar) { | ||
assert(foo === 'foo'); | ||
assert(bar === 'bar'); | ||
function onSignal(foo: string, bar: string) { | ||
assert(foo === "foo"); | ||
assert(bar === "bar"); | ||
} | ||
@@ -53,16 +44,16 @@ ``` | ||
``` | ||
var myObject = { | ||
foo: 'bar', | ||
updated: new MiniSignal() | ||
} | ||
```ts | ||
const myObject = { | ||
foo: "bar", | ||
updated: new MiniSignal<never>(), | ||
}; | ||
myObject.updated.add(onUpdated,myObject); //add listener with context | ||
myObject.updated.add(onUpdated, myObject); //add listener with context | ||
myObject.foo = 'baz'; | ||
myObject.updated.dispatch(); //dispatch signal | ||
myObject.foo = "baz"; | ||
myObject.updated.dispatch(); //dispatch signal | ||
function onUpdated() { | ||
assert(this === myObject); | ||
assert(this.foo === 'baz'); | ||
assert(this.foo === "baz"); | ||
} | ||
@@ -77,4 +68,4 @@ ``` | ||
Copyright (c) 2015 Jayson Harshbarger | ||
Copyright (c) 2015-2023 Jayson Harshbarger | ||
MIT License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
41055
15
971
0
23
69
1