You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

71 line
2.3 KiB

  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  6. var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
  7. var _react = require("react");
  8. var _setDisplayName = _interopRequireDefault(require("./setDisplayName"));
  9. var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName"));
  10. var _mapValues = _interopRequireDefault(require("./utils/mapValues"));
  11. /* eslint-disable no-console */
  12. var withHandlers = function withHandlers(handlers) {
  13. return function (BaseComponent) {
  14. var factory = (0, _react.createFactory)(BaseComponent);
  15. var WithHandlers =
  16. /*#__PURE__*/
  17. function (_Component) {
  18. (0, _inheritsLoose2.default)(WithHandlers, _Component);
  19. function WithHandlers() {
  20. var _this;
  21. for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
  22. _args[_key] = arguments[_key];
  23. }
  24. _this = _Component.call.apply(_Component, [this].concat(_args)) || this;
  25. _this.handlers = (0, _mapValues.default)(typeof handlers === 'function' ? handlers(_this.props) : handlers, function (createHandler) {
  26. return function () {
  27. var handler = createHandler(_this.props);
  28. if (process.env.NODE_ENV !== 'production' && typeof handler !== 'function') {
  29. console.error( // eslint-disable-line no-console
  30. 'withHandlers(): Expected a map of higher-order functions. ' + 'Refer to the docs for more info.');
  31. }
  32. return handler.apply(void 0, arguments);
  33. };
  34. });
  35. return _this;
  36. }
  37. var _proto = WithHandlers.prototype;
  38. _proto.render = function render() {
  39. return factory((0, _extends2.default)({}, this.props, this.handlers));
  40. };
  41. return WithHandlers;
  42. }(_react.Component);
  43. if (process.env.NODE_ENV !== 'production') {
  44. return (0, _setDisplayName.default)((0, _wrapDisplayName.default)(BaseComponent, 'withHandlers'))(WithHandlers);
  45. }
  46. return WithHandlers;
  47. };
  48. };
  49. var _default = withHandlers;
  50. exports.default = _default;