vvo / chainit

Turn an asynchronous JavaScript api into an asynchronous chainable JavaScript api
Other
12 stars 4 forks source link

chaining events.EventEmitter.prototype.on #12

Open kapouer opened 10 years ago

kapouer commented 10 years ago

Hi, i have

function Test() {}
util.inherits(Test, events.EventEmitter);
var ChainableTest = chainit(Test);

i'd like to use chainit on the "on" listener function:

var mytest = new ChainableTest();
mytest.on('ready').load('something')

unfortunately on() never gets called in that case. Any idea how to achieve this ?

kapouer commented 10 years ago

on(event, cb) doesn't really makes sense here, because cb can be called multiple times. OTOH once(event, cb) could be useful. However it requires a little hack to ensure the listener is registered right now and not when stack is empty, see for example https://github.com/kapouer/node-webkitgtk/commit/e0da6a6bea9a7efd11648ae16034fcb5cf79d4d7