javascript - Bridge two event listeners with a single event -
i trying "bridge" 2 event listeners trigger them single event. moreover, during "chain" pass values arguments listeners follow.
i tried implement follows
var events = require('events'); var receiv = new events.eventemitter(); var midl = new events.eventemitter(); receiv.on("test", function() { console.log("here", arguments); }); midl.on("test", receiv.on.bind(receiv, "test", "foo", "bar")); midl.emit("test", 123);
yet approach seems bug eventemitter getting following error
typeerror: listener must function @ typeerror (<anonymous>) @ eventemitter.addlistener (events.js:130:11) @ eventemitter.emit (events.js:95:17) @ object.<anonymous> (myeventtest.js:12:6) @ module._compile (module.js:456:26) @ object.module._extensions..js (module.js:474:10) @ module.load (module.js:356:32) @ function.module._load (module.js:312:12) @ function.module.runmain (module.js:497:10) @ startup (node.js:119:16)
cheers.
p.s. use node v0.10.5
sorry self answer, found solution.
var events = require('events'); var receiv = new events.eventemitter(); var midl = new events.eventemitter(); receiv.on("test", function() { console.log("here", arguments); }); midl.on("test", receiv.emit.bind(receiv, "test", "foo", "bar")); midl.emit("test", 123);
Comments
Post a Comment