UNPKG

4.4 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
9var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
10
11var _react = require('react');
12
13var _react2 = _interopRequireDefault(_react);
14
15var _lodash = require('lodash');
16
17var _lodash2 = _interopRequireDefault(_lodash);
18
19var _hoistNonReactStatics = require('hoist-non-react-statics');
20
21var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics);
22
23var _linkClass = require('./linkClass');
24
25var _linkClass2 = _interopRequireDefault(_linkClass);
26
27function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
29function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
30
31function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
32
33function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint-disable react/prop-types */
34
35/**
36 * @param {ReactClass} Component
37 * @param {Object} defaultStyles
38 * @param {Object} options
39 * @returns {ReactClass}
40 */
41
42exports.default = function (Component, defaultStyles, options) {
43 var WrappedComponent = function (_Component) {
44 _inherits(WrappedComponent, _Component);
45
46 function WrappedComponent() {
47 _classCallCheck(this, WrappedComponent);
48
49 return _possibleConstructorReturn(this, Object.getPrototypeOf(WrappedComponent).apply(this, arguments));
50 }
51
52 _createClass(WrappedComponent, [{
53 key: 'render',
54 value: function render() {
55 var propsChanged = void 0,
56 styles = void 0;
57
58 propsChanged = false;
59
60 if (this.props.styles) {
61 styles = this.props.styles;
62 } else if (_lodash2.default.isObject(defaultStyles)) {
63 this.props = _lodash2.default.assign({}, this.props, {
64 styles: defaultStyles
65 });
66
67 propsChanged = true;
68 styles = defaultStyles;
69 } else {
70 styles = {};
71 }
72
73 var renderResult = _get(Object.getPrototypeOf(WrappedComponent.prototype), 'render', this).call(this);
74
75 if (propsChanged) {
76 delete this.props.styles;
77 }
78
79 if (renderResult) {
80 return (0, _linkClass2.default)(renderResult, styles, options);
81 }
82
83 return _react2.default.createElement('noscript');
84 }
85 }]);
86
87 return WrappedComponent;
88 }(Component);
89
90 return (0, _hoistNonReactStatics2.default)(WrappedComponent, Component);
91};
92
93module.exports = exports['default'];
\No newline at end of file