bare-events
Advanced tools
Comparing version 2.2.2 to 2.3.0
33
index.js
@@ -291,1 +291,34 @@ const errors = require('./lib/errors') | ||
} | ||
exports.forward = function forward (from, to, ...names) { | ||
let opts = names.pop() | ||
if (typeof opts === 'string') { | ||
names.push(opts) | ||
opts = {} | ||
} | ||
const { | ||
emit = to.emit.bind(to) | ||
} = opts | ||
const listeners = names.map((name) => function onevent (...args) { | ||
emit(name, ...args) | ||
}) | ||
to | ||
.on('newListener', (name) => { | ||
const i = names.indexOf(name) | ||
if (i !== -1 && to.listenerCount(name) === 0) { | ||
from.on(name, listeners[i]) | ||
} | ||
}) | ||
.on('removeListener', (name) => { | ||
const i = names.indexOf(name) | ||
if (i !== -1 && to.listenerCount(name) === 0) { | ||
from.off(name, listeners[i]) | ||
} | ||
}) | ||
} |
{ | ||
"name": "bare-events", | ||
"version": "2.2.2", | ||
"version": "2.3.0", | ||
"description": "Event emitters for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "index.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
19599
260