flux
flux copied to clipboard
Why is EventEmitter prototype included in store prototype?
Wouldn't something like the following encourage better encapsulation?
var _emitter = new EventEmitter();
var MyStore = {
emitChange() {
_emitter.emit('change');
},
addChangeListener(callback) {
_emitter.on('change', callback);
},
removeChangeListener(callback) {
_emitter.removeListener('change', callback);
}
};
I'm not sure this would even run.
You might be saying that we should be using ES6 classes? And I would agree, generally, but the examples are intended to be instructional to the widest possible audiece, so they are written in ES5. It would be worth publishing an ES6 version of he Flux examples just so people could see how we really write code at FB.