doxout/recluster

Maybe emit() function can become more clear?

frankLife opened this issue · 2 comments

The question is about emit() function.

var self = new EE();
var channel = new EE();

function emit() {
    channel.emit.apply(self, arguments);
    self.emit.apply(channel, arguments);
}

According to the source code,We get two instances of EventEmitter class and use emit function to redirect messages.

But why we use channel object to emit events of self object whereas use self object to emit events of channel object?

  1. It seems like that we don't bind any event on self object.

  2. I change the function as below

    function emit() {
        channel.emit.apply(channel, arguments);
    }
    

the module also can invoke run() and reload() function.

If there is no other design about it,maybe this is a better clear way.

Thats actually a bug which doesn't do any harm. Its the same emit function applied to both channel and self. Should probably be

    self.emit.apply(self, arguments);
    channel.emit.apply(channel, arguments);

Channel is an internal event channel for recluster, while self exposes events to the outside world (not documented yet).

The reason why there is an internal channel is to prevent methods like EventEmitter.removeAllListeners and similar from breaking recluster (the internal channel is never exposed so its impossible to indadvertedly remove its listeners)

Well.Internal channel is good.Thanks.