Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eventyoshi

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventyoshi - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

24

lib/index.js

@@ -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');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc