/* @jsx h */
export const _Container = vdom => {
  const h = vdom.h || vdom.createElement;
  return class Container extends vdom.Component {
    static childContextTypes = {
      store: () => {}
    };

    getChildContext() {
      return {
        store: this.props.store
      };
    }

    constructor(props) {
      super(props);
      if (!props.store) throw new Error("Store not found");
    }

    render() {
      const { children, store, ...rest } = this.props; // eslint-disable-line no-unused-vars
      return <div {...rest}>{children}</div>;
    }
  };
};

export const _mapper = vdom => {
  const h = vdom.h || vdom.createElement;

  return (propMappings = {}, actionMappings = {}) => Wrapped => {
    return class Mapper extends vdom.Component {
      static contextTypes = {
        store: () => {}
      };

      constructor(props, context) {
        super(props, context);
        this.unsubscribe = this.store.subscribe(this.handleStoreUpdate);
        this.mappedProps = {};
        for (const key in propMappings) {
          this.mappedProps[key] = propMappings[key](this.store, this.props);
        }

        this.mappedActions = {};
        for (const key in actionMappings) {
          this.mappedActions[key] = (...args) =>
            actionMappings[key](this.store, this.props, ...args);
        }
      }

      get store() {
        const store = this.props.store || this.context.store;
        if (!store) throw new Error("Store not found");
        return store;
      }

      shouldComponentUpdate() {
        return false;
      }

      componentWillUnmount() {
        this.unsubscribe();
      }

      handleStoreUpdate = () => {
        let hasPropsChanged = false;
        for (const key in propMappings) {
          const prop = propMappings[key](this.store, this.props);
          if (prop !== this.mappedProps[key]) hasPropsChanged = true;
          this.mappedProps[key] = prop;
        }

        if (hasPropsChanged) this.forceUpdate();
      };

      render() {
        return (
          <Wrapped
            {...this.props}
            {...this.mappedProps}
            {...this.mappedActions}
          />
        );
      }
    };
  };
};

@@ -887,16 +887,70 @@
 ntext);%0A
+        if (Object.keys(propMappings).length !== 0)%0A  
         
@@ -1014,16 +1014,17 @@
 pdate);%0A
+%0A
         
@@ -1584,16 +1584,25 @@
 tUpdate(
+nextProps
 ) %7B%0A    
@@ -1609,89 +1609,280 @@
     
-return false;%0A      %7D%0A%0A      componentWillUnmount() %7B%0A        this.unsubscribe();
+for (const key in nextProps) %7B%0A          if (this.props%5Bkey%5D !== nextProps%5Bkey%5D) return true;%0A        %7D%0A        return false;%0A      %7D%0A%0A      componentWillUnmount() %7B%0A        if (this.unsubscribe) %7B%0A          this.unsubscribe();%0A          this.unsubscribe = null;%0A        %7D
 %0A   

check for prop changes in mapped container component