eventproxy
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -18,3 +18,3 @@ /*global exports */ | ||
// Node.js Module | ||
module.exports = definition(); | ||
module.exports = definition(require('debug')('eventproxy')); | ||
} else { | ||
@@ -24,3 +24,4 @@ // Assign to common namespaces or simply the global object (window) | ||
} | ||
})('EventProxy', function () { | ||
})('EventProxy', function (debug) { | ||
debug = debug || function () {}; | ||
@@ -56,2 +57,3 @@ /** | ||
EventProxy.prototype.addListener = function (ev, callback) { | ||
debug('Add listener for %s', ev); | ||
this._callbacks = this._callbacks || {}; | ||
@@ -85,5 +87,7 @@ this._callbacks[ev] = this._callbacks[ev] || []; | ||
if (!ev) { | ||
debug('Remove all listeners'); | ||
this._callbacks = {}; | ||
} else if (calls) { | ||
if (!callback) { | ||
ev!== 'all' && debug('Remove all listeners of %s', ev); | ||
calls[ev] = []; | ||
@@ -98,2 +102,3 @@ } else { | ||
if (callback === list[i]) { | ||
ev!== 'all' && debug('Remove a listener of %s', ev); | ||
list[i] = null; | ||
@@ -132,2 +137,3 @@ break; | ||
var calls = this._callbacks; | ||
debug('Emit event %s with data %j', eventName, data); | ||
while (both--) { | ||
@@ -225,3 +231,3 @@ ev = both ? eventName : 'all'; | ||
} | ||
debug('Assign listener for events %j, once is %s', events, !!isOnce); | ||
length = events.length; | ||
@@ -258,2 +264,3 @@ bind = function (key) { | ||
} | ||
debug('Events %j all emited with data %j', events, data); | ||
callback.apply(null, data); | ||
@@ -348,2 +355,3 @@ }; | ||
}; | ||
debug('After emit %s times, event %s\'s listenner will execute', times, eventName); | ||
all = function (name, data) { | ||
@@ -354,2 +362,3 @@ if (name === eventName) { | ||
if (times < 1) { | ||
debug('Event %s was emit %s, and execute the listenner', eventName, times); | ||
proxy.unbind("all", all); | ||
@@ -363,2 +372,3 @@ callback.apply(null, [firedData]); | ||
if (times < 1) { | ||
debug('Event %s was emit %s, and execute the listenner', eventName, times); | ||
proxy.unbind("all", all); | ||
@@ -400,3 +410,4 @@ callback.call(null, proxy._after[group].results); | ||
index: index, | ||
result: callback ? callback(data) : data | ||
// callback(err, args1, args2, ...) | ||
result: callback ? callback.apply(null, Array.prototype.slice.call(arguments, 1)) : data | ||
}); | ||
@@ -422,2 +433,3 @@ }; | ||
debug('Add listenner for Any of events %j emit', events); | ||
proxy.once(_eventName, callback); | ||
@@ -427,2 +439,3 @@ | ||
proxy.bind(key, function (data) { | ||
debug('One of events %j emited, execute the listenner'); | ||
proxy.trigger(_eventName, {"data": data, eventName: key}); | ||
@@ -444,4 +457,6 @@ }); | ||
var proxy = this; | ||
debug('Add listenner for not event %s', eventName); | ||
proxy.bind("all", function (name, data) { | ||
if (name !== eventName) { | ||
debug('listenner execute of event %s emit, but not event %s.', name, eventName); | ||
callback(data); | ||
@@ -448,0 +463,0 @@ } |
@@ -16,5 +16,9 @@ { | ||
], | ||
"dependencies": {}, | ||
"dependencies": { | ||
"debug": "0.7.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"mocha-phantomjs": "*", | ||
"component": "*", | ||
"blanket": "*", | ||
@@ -34,3 +38,3 @@ "pedding": "*", | ||
"travis-cov": { | ||
"threshold": 70 | ||
"threshold": 97 | ||
} | ||
@@ -42,3 +46,3 @@ }, | ||
}, | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"main": "index.js", | ||
@@ -45,0 +49,0 @@ "directories": { |
@@ -73,2 +73,9 @@ EventProxy [![Build Status](https://secure.travis-ci.org/JacksonTian/eventproxy.png)](http://travis-ci.org/JacksonTian/eventproxy) [![NPM version](https://badge.fury.io/js/eventproxy.png)](http://badge.fury.io/js/eventproxy) [English Doc](https://github.com/JacksonTian/eventproxy/blob/master/README_en.md) | ||
``` | ||
### Component | ||
```bash | ||
$ component install JacksonTian/eventproxy | ||
``` | ||
### 前端用户 | ||
@@ -517,1 +524,6 @@ 以下示例均指向Github的源文件地址,您也可以[下载源文件](https://raw.github.com/JacksonTian/eventproxy/master/lib/eventproxy.js)到你自己的项目中。整个文件注释全面,带注释和空行,一共约500行。为保证EventProxy的易嵌入,项目暂不提供压缩版。用户可以自行采用Uglify、YUI Compressor或Google Closure Complier进行压缩。 | ||
[The MIT License](https://github.com/JacksonTian/eventproxy/blob/master/MIT-License)。请自由享受开源。 | ||
## 捐赠 | ||
如果您觉得本模块对您有帮助,欢迎请作者一杯咖啡 | ||
[![捐赠EventProxy](https://img.alipay.com/sys/personalprod/style/mc/btn-index.png)](https://me.alipay.com/jacksontian) |
Sorry, the diff of this file is not supported yet
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
50100
8
549
528
1
7
+ Addeddebug@0.7.2
+ Addeddebug@0.7.2(transitive)