nanoevents
Advanced tools
Comparing version 0.3.0 to 0.4.0
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 0.4 | ||
* Add `nanoevents/unbind-all` helper (by Igor Deryabin). | ||
* Fix JSDoc (by Igor Deryabin). | ||
* Reduce size. | ||
## 0.3 | ||
@@ -5,0 +10,0 @@ * Allow to change listeners during the emit. |
16
index.js
@@ -22,3 +22,3 @@ /** | ||
*/ | ||
module.exports = function NanoEvents () { | ||
function NanoEvents () { | ||
/** | ||
@@ -36,3 +36,3 @@ * Event names in keys and arrays with listeners in values. | ||
if (typeof cb !== 'function') { | ||
throw new Error('Expected event listener to be a function') | ||
throw new Error('Listener must be a function') | ||
} | ||
@@ -62,3 +62,3 @@ | ||
module.exports.prototype = { | ||
NanoEvents.prototype = { | ||
@@ -122,8 +122,5 @@ /** | ||
var args = new Array(arguments.length - 1) | ||
for (var i = 1; i < arguments.length; i++) { | ||
args[i - 1] = arguments[i] | ||
} | ||
var args = [].slice.call(arguments, 1) | ||
for (i = 0; i < copy.length; i++) { | ||
for (var i = 0; i < copy.length; i++) { | ||
var l = copy[i] | ||
@@ -136,3 +133,4 @@ l.fn.apply(this, args) | ||
} | ||
} | ||
} | ||
module.exports = NanoEvents |
{ | ||
"name": "nanoevents", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Small and simple events API", | ||
@@ -20,28 +20,30 @@ "keywords": [ | ||
"repository": "ai/nanoevents", | ||
"dependencies": { }, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"docdash": "^0.4.0", | ||
"eslint": "^3.10.2", | ||
"eslint-config-standard": "^6.2.1", | ||
"eslint-plugin-promise": "^3.4.0", | ||
"eslint-plugin-standard": "^2.0.1", | ||
"jest": "^17.0.3", | ||
"jsdoc": "^3.4.3", | ||
"lint-staged": "^3.2.1", | ||
"pre-commit": "^1.1.3", | ||
"rimraf": "^2.5.4", | ||
"uglifyjs": "^2.4.10", | ||
"yaspeller": "^3.0.0" | ||
"eslint": "^4.6.1", | ||
"eslint-config-logux": "^16.1.1", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-es5": "^1.1.0", | ||
"eslint-plugin-import": "^2.7.0", | ||
"eslint-plugin-jest": "^21.0.2", | ||
"eslint-plugin-node": "^5.1.1", | ||
"eslint-plugin-promise": "^3.5.0", | ||
"eslint-plugin-security": "^1.4.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"jest": "^21.0.2", | ||
"jsdoc": "^3.5.4", | ||
"lint-staged": "^4.1.3", | ||
"pre-commit": "^1.2.2", | ||
"rimraf": "^2.6.1", | ||
"size-limit": "^0.11.1", | ||
"yaspeller-ci": "^0.6.0" | ||
}, | ||
"scripts": { | ||
"lint-staged": "lint-staged", | ||
"spellcheck": "npm run cleandocs && yaspeller *.md docs/*.html", | ||
"cleandocs": "npm run docs && rimraf docs/*.js.html", | ||
"clean": "rimraf docs/ coverage/ *.gz", | ||
"spellcheck": "yarn docs && yaspeller-ci *.md docs/*.html", | ||
"clean": "rimraf docs/ coverage/", | ||
"lint": "eslint *.js test/*.js", | ||
"docs": "jsdoc --configure .jsdocrc *.js", | ||
"test": "jest --coverage && npm run lint && npm run spellcheck", | ||
"compress": "uglifyjs index.js -o min.js && gzip -9 -f min.js", | ||
"show": "ls -lh *.gz | awk '{print \"Size:\", $5\"B\"}'", | ||
"size": "npm run compress && npm run show && rm *.gz" | ||
"test": "jest --coverage && yarn lint && size-limit && yarn spellcheck" | ||
}, | ||
@@ -55,17 +57,16 @@ "jest": { | ||
}, | ||
"engines": { | ||
"node": ">=4.0.0" | ||
}, | ||
"eslintConfig": { | ||
"extends": "standard", | ||
"rules": { | ||
"valid-jsdoc": "error", | ||
"max-len": [ | ||
2, | ||
80 | ||
] | ||
}, | ||
"env": { | ||
"jest": true | ||
"extends": "eslint-config-logux/browser" | ||
}, | ||
"size-limit": [ | ||
{ | ||
"path": "index.js", | ||
"limit": "270 B" | ||
} | ||
}, | ||
], | ||
"lint-staged": { | ||
"*.md": "yaspeller", | ||
"*.md": "yaspeller-ci", | ||
"*.js": "eslint" | ||
@@ -72,0 +73,0 @@ }, |
@@ -6,3 +6,3 @@ # Nano Events | ||
* No node.js [EventEmitter] compatibility. | ||
* Only 447 bytes (minified and gzipped). | ||
* Only 270 bytes (minified and gzipped). It uses [Size Limit] to control size. | ||
* `on` and `once` methods return `unbind` function. You don’t need to save | ||
@@ -28,2 +28,5 @@ callback to variable for `removeListener`. | ||
[EventEmitter]: https://nodejs.org/api/events.html | ||
[Size Limit]: https://github.com/ai/size-limit | ||
<a href="https://evilmartians.com/?utm_source=nanoevents"> | ||
@@ -34,2 +37,3 @@ <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" | ||
## Usage | ||
@@ -59,2 +63,3 @@ | ||
### Add Listener | ||
@@ -79,2 +84,3 @@ | ||
### Remove Listener | ||
@@ -98,2 +104,3 @@ | ||
### Execute Listeners | ||
@@ -112,2 +119,3 @@ | ||
### Events List | ||
@@ -125,2 +133,18 @@ | ||
[EventEmitter]: https://nodejs.org/api/events.html | ||
### Helpers | ||
#### Remove all listeners | ||
`unbindAll` method will remove all listeners to all events. | ||
```js | ||
import unbindAll from 'nanoevents/unbind-all'; | ||
emitter.on('event1', () => { }) | ||
emitter.on('event2', () => { }) | ||
unbindAll(emitter); | ||
Object.keys(emitter.events) //=> { } | ||
``` |
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
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
8699
6
131
143
18