/* @flow */

var EventManager = require('../core/events/EventManager.js');
var StoreFacade = require('../store/StoreFacade.js');

var StoreListenerMixin = {

  componentWillMount(): void {
    if (process.env.NODE_ENV !== 'production') {
      if (typeof this.getStoreState !== 'function') {
        throw new Error(
          'StoreListenerMixin: expected this.getStoreState to be a function.'
        )
      }
    }
    this.handleStoreChange = this.handleStoreChange.bind(this);
    this.stores.forEach(
      store => store.addOnChange(this.handleStoreChange)
    );
    this.handleStoreChange();
  },

  componentWillUnmount(): void {
    this.stores.forEach(
      store => store.removeOnChange(this._handleStoreChange)
    );
  },

  handleStoreChange(): void {
    this.setState(
      this.getStoreState()
    );
  }

  /**
   * // an array of StoreFacades
   * stores: [
   *   ExampleStore
   * ],
   */

  /**
   * // the return value of getStoreState will be merged
   * // into the component state
   * getStoreState(): Object {
   *   return {
   *     exampleData: ExampleStore.get()
   *   };
   * }
   */

};

module.exports = StoreListenerMixin;

@@ -10,70 +10,8 @@
 */%0A%0A
-var EventManager = require('../core/events/EventManager.js');%0A
 var 
@@ -340,24 +340,331 @@
   )%0A      %7D%0A
+      if (!Array.isArray(this.stores)) %7B%0A        throw new Error(%0A          'StoreListenerMixin: this.stores must be an array of stores.'%0A        );%0A      %7D%0A      if (this.stores.length %3C 1) %7B%0A        throw new Error(%0A          'StoreListenerMixin: no stores are defined in this.stores.'%0A        );%0A      %7D%0A
     %7D%0A    th

revert StoreListenerMixin