Search code examples
javascriptreactjsflux

I can't find the definition of the 'on' method in flux example, todomvc. what does it do?


on line 107 of TodoStore.js:

   /**
   * @param {function} callback
   */
  addChangeListener: function(callback) {
    this.on(CHANGE_EVENT, callback);
  },

link: https://github.com/facebook/flux/blob/master/examples/flux-todomvc/js/stores/TodoStore.js


Solution

  • The example is using the Node Events module, which defines EventEmitter. The two lines that show you what is going on are:

    var EventEmitter = require('events').EventEmitter;
    

    And…

    var TodoStore = assign({}, EventEmitter.prototype, {