import React from 'react';
import ReactDOM from 'react-dom';

/**
 * @param {ReactClass} Target The component that defines `onOutsideEvent` handler.
 * @param {String[]} supportedEvents A list of valid DOM event names. Default: ['mousedown'].
 * @return {ReactClass}
 */
export default (Target, supportedEvents = ['mousedown']) => {
    return class ReactOutsideEvent extends React.Component {
        componentDidMount = () => {
            if (!this.refs.target.onOutsideEvent) {
                throw new Error('Component does not define "onOutsideEvent" method.');
            }

            supportedEvents.forEach((eventName) => {
                window.addEventListener(eventName, this.handleEvent, false);
            });
        };

        componentWillUnmount = () => {
            supportedEvents.forEach((eventName) => {
                window.removeEventListener(eventName, this.handleEvent, false);
            });
        };

        handleEvent = (event) => {
            let isInside,
                isOutside,
                target,
                targetElement;
            target = this.refs.target;
            targetElement = ReactDOM.findDOMNode(target);
            if(targetElement != undefined) {
              isInside = targetElement.contains(event.target) || targetElement === event.target;
              isOutside = !isInside;

              if (isOutside) {
                  target.onOutsideEvent(event);
              }
            }
        };

        render() {
            return <Target ref='target' {... this.props} />;
        }
    };
};

@@ -1220,37 +1220,14 @@
 ined
-) %7B%0A              isInside = 
+ && !(
 targ
@@ -1262,115 +1262,13 @@
 get)
- %7C%7C targetElement === event.target;%0A              isOutside = !isInside;%0A%0A              if (isOutside
+)
 ) %7B%0A
-  
     
@@ -1313,24 +1313,8 @@
 t);%0A
-              %7D%0A
     

simplified isOutside check