async-glob-events
Advanced tools
Comparing version 0.2.0 to 1.0.0
# Changes | ||
## 1.0.0 | ||
- Use `glob-events` 1.0 | ||
- Allow to configure the scope to use on listener registration | ||
## 0.2.0 | ||
- Bump glob-events to 0.5.0 | ||
- Bump `glob-events` to 0.5 | ||
@@ -7,0 +12,0 @@ ## 0.1.1 |
@@ -59,3 +59,3 @@ /* | ||
function createListener(fn) { | ||
function createListener(fn, scope) { | ||
if (typeof fn !== 'function') { | ||
@@ -65,23 +65,20 @@ throw new TypeError(E_LISTENER); | ||
return function () { | ||
var res; | ||
var res, args, cb; | ||
if (fn.length > arguments.length) { | ||
var args = this.args.slice(); | ||
var cb = this.callback(); | ||
cb = this.callback(); | ||
args = this.args.slice(); | ||
args[fn.length - 1] = cb; | ||
try { | ||
res = fn.apply(this, args); | ||
if (res !== undefined) { | ||
cb(null, res); | ||
} | ||
} catch (err) { | ||
cb(err); | ||
} | ||
} else { | ||
try { | ||
res = fn.apply(this, arguments); | ||
if (res !== undefined) { | ||
this.callback.push(res); | ||
} | ||
} catch (err) { | ||
this.callback.err(err); | ||
args = arguments; | ||
} | ||
try { | ||
res = fn.apply(scope || this, args); | ||
} catch (err) { | ||
(cb || this.callback.err)(err); | ||
} | ||
if (res !== undefined) { | ||
if (cb) { | ||
cb(null, res); | ||
} else { | ||
this.callback.push(res); | ||
} | ||
@@ -93,16 +90,28 @@ } | ||
AyncEmitter.prototype.addListener = function (event, fn) { | ||
var l = createListener(fn); | ||
l._once = fn; | ||
addListener.call(this, event, l); | ||
var o = { orig : fn }; | ||
var s; | ||
if (typeof event === 'string') { | ||
o.event = event; | ||
} else { | ||
o.event = event.event; | ||
s = event.scope; | ||
} | ||
addListener.call(this, o, createListener(fn, s)); | ||
}; | ||
AyncEmitter.prototype.once = function (event, fn) { | ||
var l = createListener(fn); | ||
var s = this._store; | ||
var f = function () { | ||
s.remove(event, f); | ||
var t = this; | ||
var o = { orig : fn }; | ||
var s; | ||
if (typeof event === 'string') { | ||
o.event = event; | ||
} else { | ||
o.event = event.event; | ||
s = event.scope; | ||
} | ||
var l = createListener(fn, s); | ||
addListener.call(this, o, function () { | ||
t.removeListener(o.event, fn); | ||
l.apply(this, arguments); | ||
}; | ||
f._once = fn; | ||
addListener.call(this, event, f); | ||
}); | ||
}; | ||
@@ -109,0 +118,0 @@ |
{ | ||
"name" : "async-glob-events", | ||
"version" : "0.2.0", | ||
"version" : "1.0.0", | ||
"description" : "Event emitter with glob support on event names and asynchronous listeners", | ||
@@ -14,4 +14,4 @@ "keywords" : ["event", "emitter", "glob", "listener", "async", "return values"], | ||
"start" : "mocha --watch", | ||
"lint" : "jslint --color './**/*.js'", | ||
"test-wd" : "mochify --wd", | ||
"lint" : "jslint --color \"**/*.js\"", | ||
"wd" : "mochify --wd", | ||
"test" : "npm run lint && mocha && mochify --cover" | ||
@@ -24,10 +24,10 @@ }, | ||
"dependencies" : { | ||
"inherits" : "^2.0.1", | ||
"listen" : "^1.0.0", | ||
"glob-events" : "~0.5.0" | ||
"inherits" : "^2.0", | ||
"listen" : "^1.0", | ||
"glob-events" : "^1.0" | ||
}, | ||
"devDependencies" : { | ||
"mocha" : "^1.17.0", | ||
"jslint" : "~0.3.3", | ||
"mochify" : "~0.9.0" | ||
"mocha" : "^1.21", | ||
"jslint" : "^0.6", | ||
"mochify" : "^1.1" | ||
}, | ||
@@ -34,0 +34,0 @@ "files" : ["lib", "README.md", "CHANGES.md", "LICENSE"], |
@@ -1,13 +0,13 @@ | ||
# async-glob-events.js [![Build Status](https://travis-ci.org/mantoni/async-glob-events.js.png?branch=master)](http://travis-ci.org/mantoni/async-glob-events.js) | ||
# async-glob-events.js | ||
[![Build Status]](https://travis-ci.org/mantoni/async-glob-events.js) | ||
[![SemVer]](http://semver.org) | ||
[![License]](https://github.com/mantoni/async-glob-events.js/blob/master/LICENSE) | ||
Event emitter with glob support on event names and asynchronous listeners, for | ||
node and the browser | ||
Repository: <https://github.com/mantoni/async-glob-events.js> | ||
--- | ||
## Features | ||
- Inherits the features from [glob-events][] | ||
- Inherits all features from [glob-events][] | ||
- Pass a callback as the last argument to `emit` and receive asynchronous | ||
@@ -17,2 +17,12 @@ errors and return values from listeners | ||
## Install with npm | ||
``` | ||
npm install async-glob-events | ||
``` | ||
## Browser support | ||
Use [Browserify](http://browserify.org) to create a standalone file. | ||
## Usage | ||
@@ -57,12 +67,2 @@ | ||
## Install with npm | ||
``` | ||
npm install async-glob-events | ||
``` | ||
## Browser support | ||
Use [Browserify](http://browserify.org) to create a standalone file. | ||
## License | ||
@@ -72,2 +72,5 @@ | ||
[Build Status]: http://img.shields.io/travis/mantoni/async-glob-events.js.svg | ||
[SemVer]: http://img.shields.io/:semver-%E2%9C%93-brightgreen.svg | ||
[License]: http://img.shields.io/npm/l/async-glob-events.svg | ||
[glob-events]: https://github.com/mantoni/glob-events.js |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6902
107
0
74
+ Addedglob-events@1.6.0(transitive)
+ Addedglob-store@1.0.0(transitive)
+ Addedglob-tree@1.0.0(transitive)
+ Addedlive-list@1.0.0(transitive)
+ Addedlive-tree@1.0.0(transitive)
+ Addedmin-iterator@1.0.0(transitive)
- Removedglob-events@0.5.0(transitive)
- Removedglob-store@0.2.0(transitive)
- Removedglob-tree@0.4.2(transitive)
- Removedlive-list@0.3.0(transitive)
- Removedlive-tree@0.3.0(transitive)
- Removedmin-iterator@0.1.1(transitive)
Updatedglob-events@^1.0
Updatedinherits@^2.0
Updatedlisten@^1.0