'use strict';

import React from 'react';
import shallowEqual from 'react/lib/shallowEqual';

export default function connectToStores(Component, stores, pickProps, getState) {
  const StoreConnector = React.createClass({
    getStateFromStores(props) {
      return getState(pickProps(props));
    },

    getInitialState() {
      return this.getStateFromStores(this.props);
    },

    componentDidMount() {
      stores.forEach(store =>
        store.addChangeListener(this.handleStoresChanged)
      );

      this.setState(this.getStateFromStores(this.props));
    },

    componentWillReceiveProps(nextProps) {
      if (!shallowEqual(pickProps(nextProps), pickProps(this.props))) {
        this.setState(this.getStateFromStores(nextProps));
      }
    },

    componentWillUnmount() {
      stores.forEach(store =>
        store.removeChangeListener(this.handleStoresChanged)
      );
    },

    handleStoresChanged() {
      if (this.isMounted()) {
        this.setState(this.getStateFromStores(this.props));
      }
    },

    render() {
      return <Component {...this.props} {...this.state} />;
    }
  });

  return StoreConnector;
};

@@ -176,12 +176,12 @@
 %0A  c
-onst
+lass
  Sto
@@ -196,52 +196,49 @@
 tor 
-= React.createClass(%7B%0A    getStateFromS
+extends React.Component %7B%0A    construc
 tor
-es
 (pro
@@ -253,40 +253,51 @@
     
-return getState(pickProp
+this.state = this.getStateFromStore
 s(props)
 );%0A 
@@ -288,33 +288,31 @@
 tores(props)
-)
 ;%0A    %7D
-,
 %0A%0A    getIni
@@ -312,21 +312,29 @@
  get
-InitialState(
+StateFromStores(props
 ) %7B%0A
@@ -346,29 +346,24 @@
  return 
-this.
 getState
 FromStor
@@ -358,38 +358,33 @@
 tate
-FromStores(this.
+(pickProps(
 props)
+)
 ;%0A    %7D
-,
 %0A%0A  
@@ -485,32 +485,43 @@
 dleStoresChanged
+.bind(this)
 )%0A      );%0A%0A    
@@ -575,25 +575,24 @@
 ops));%0A    %7D
-,
 %0A%0A    compon
@@ -764,25 +764,24 @@
      %7D%0A    %7D
-,
 %0A%0A    compon
@@ -888,16 +888,27 @@
 sChanged
+.bind(this)
 )%0A      
@@ -911,25 +911,24 @@
     );%0A    %7D
-,
 %0A%0A    handle
@@ -949,40 +949,8 @@
 ) %7B%0A
-      if (this.isMounted()) %7B%0A  
     
@@ -1011,18 +1011,9 @@
     
-  %7D%0A    %7D,
+%7D
 %0A%0A  
@@ -1094,18 +1094,16 @@
    %7D%0A  %7D
-);
 %0A%0A  retu

Migrate connectToStores