text: "use strict";
  var __assign = (this && this.__assign) || function () {
      __assign = Object.assign || function(t) {
          for (var s, i = 1, n = arguments.length; i < n; i++) {
              s = arguments[i];
              for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                  t[p] = s[p];
          }
          return t;
      };
      return __assign.apply(this, arguments);
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  var react_1 = require("react");
  var staticRendering_1 = require("./staticRendering");
  var useObserver_1 = require("./useObserver");
  // n.b. base case is not used for actual typings or exported in the typing files
  function observer(baseComponent, options) {
      // The working of observer is explained step by step in this talk: https://www.youtube.com/watch?v=cPF4iBedoF0&feature=youtu.be&t=1307
      if (staticRendering_1.isUsingStaticRendering()) {
          return baseComponent;
      }
      var realOptions = __assign({ forwardRef: false }, options);
      var baseComponentName = baseComponent.displayName || baseComponent.name;
      var wrappedComponent = function (props, ref) {
          return useObserver_1.useObserver(function () { return baseComponent(props, ref); }, baseComponentName);
      };
      wrappedComponent.displayName = baseComponentName;
      // memo; we are not interested in deep updates
      // in props; we assume that if deep objects are changed,
      // this is in observables, which would have been tracked anyway
      var memoComponent;
      if (realOptions.forwardRef) {
          // we have to use forwardRef here because:
          // 1. it cannot go before memo, only after it
          // 2. forwardRef converts the function into an actual component, so we can't let the baseComponent do it
          //    since it wouldn't be a callable function anymore
          memoComponent = react_1.memo(react_1.forwardRef(wrappedComponent));
      }
      else {
          memoComponent = react_1.memo(wrappedComponent);
      }
      copyStaticProperties(baseComponent, memoComponent);
      memoComponent.displayName = baseComponentName;
      return memoComponent;
  }
  exports.observer = observer;
  // based on https://github.com/mridgway/hoist-non-react-statics/blob/master/src/index.js
  var hoistBlackList = {
      $$typeof: true,
      render: true,
      compare: true,
      type: true
  };
  function copyStaticProperties(base, target) {
      Object.keys(base).forEach(function (key) {
          if (!hoistBlackList[key]) {
              Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(base, key));
          }
      });
  }
  