flux icon indicating copy to clipboard operation
flux copied to clipboard

Why is EventEmitter prototype included in store prototype?

Open ronag opened this issue 12 years ago • 2 comments

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);
   }

};

ronag avatar Nov 28 '14 13:11 ronag

I'm not sure this would even run.

sterpe avatar Nov 28 '14 17:11 sterpe

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.

fisherwebdev avatar Dec 21 '14 07:12 fisherwebdev