eventyoshi
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -259,9 +259,19 @@ var EventEmitter = require('events').EventEmitter | ||
// | ||
yoshi.prototype.proxy = function(fn) { | ||
this[fn] = function() { | ||
var args = arguments; | ||
this.children.forEach(function(ee) { | ||
ee[fn].apply(ee, args); | ||
}); | ||
}; | ||
yoshi.prototype.proxy = function() { | ||
var self = this; | ||
Array.prototype.slice.call(arguments).forEach(function(fn) { | ||
self[fn] = function() { | ||
var args = arguments; | ||
var rs = []; | ||
self.children.forEach(function(ee) { | ||
if (typeof ee[fn] === 'function') { | ||
rs.push(ee[fn].apply(ee, args)); | ||
} | ||
}); | ||
return rs.length === 1 ? rs[0] : rs; | ||
}; | ||
}); | ||
}; |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["event", "emitter", "eventemitter", "router", "proxy"], | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -70,9 +70,10 @@ # eventyoshi [![Build Status](https://secure.travis-ci.org/fent/node-eventyoshi.png)](http://travis-ci.org/fent/node-eventyoshi) | ||
### yoshi.proxy(fn) | ||
Proxies all calls from to `yoshi[fn]` to its children. | ||
Proxies all calls from to `yoshi[fn]` to its children. Returns values returned from called functions in an array. If the array's length is only 1, returns only the first value; | ||
```js | ||
yoshi.add(writeStream); | ||
yoshi.proxy('write'); | ||
yoshi.proxy('write', 'end'); | ||
yoshi.write(data); // this will call writeStream.write with data | ||
yoshi.write(data); // this will call writeStream.write() with data | ||
yoshi.end(); // will call writeStream.end() | ||
``` | ||
@@ -79,0 +80,0 @@ |
@@ -302,6 +302,7 @@ var EventYoshi = require('..') | ||
yoshi.proxy('foo'); | ||
yoshi.proxy('foo', 'bar'); | ||
ee1.foo = function() { | ||
ee1foo = true; | ||
return 'a'; | ||
}; | ||
@@ -311,9 +312,16 @@ | ||
ee2foo = a + b; | ||
return 'b'; | ||
}; | ||
ee2.bar = function(a) { | ||
return a; | ||
}; | ||
it('Calls proxied child functions', function() { | ||
yoshi.foo(2, 3); | ||
assert.deepEqual(yoshi.foo(2, 3), ['a', 'b']); | ||
assert.equal(ee1foo, true); | ||
assert.equal(ee2foo, 5); | ||
assert.equal(yoshi.bar('hello'), 'hello'); | ||
}); | ||
}); |
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
55312
500
116