1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _assign2 = require('lodash/assign');
|
8 |
|
9 | var _assign3 = _interopRequireDefault(_assign2);
|
10 |
|
11 | var _isObject2 = require('lodash/isObject');
|
12 |
|
13 | var _isObject3 = _interopRequireDefault(_isObject2);
|
14 |
|
15 | var _react = require('react');
|
16 |
|
17 | var _react2 = _interopRequireDefault(_react);
|
18 |
|
19 | var _hoistNonReactStatics = require('hoist-non-react-statics');
|
20 |
|
21 | var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics);
|
22 |
|
23 | var _linkClass = require('./linkClass');
|
24 |
|
25 | var _linkClass2 = _interopRequireDefault(_linkClass);
|
26 |
|
27 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
28 |
|
29 | function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
30 |
|
31 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
32 |
|
33 | function _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; }
|
34 |
|
35 | function _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) : _defaults(subClass, superClass); }
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | exports.default = function (Component, defaultStyles, options) {
|
44 | var WrappedComponent = function (_Component) {
|
45 | _inherits(WrappedComponent, _Component);
|
46 |
|
47 | function WrappedComponent() {
|
48 | _classCallCheck(this, WrappedComponent);
|
49 |
|
50 | return _possibleConstructorReturn(this, _Component.apply(this, arguments));
|
51 | }
|
52 |
|
53 | WrappedComponent.prototype.render = function render() {
|
54 | var propsChanged = void 0,
|
55 | styles = void 0;
|
56 |
|
57 | propsChanged = false;
|
58 |
|
59 | if (this.props.styles) {
|
60 | styles = this.props.styles;
|
61 | } else if ((0, _isObject3.default)(defaultStyles)) {
|
62 | this.props = (0, _assign3.default)({}, this.props, {
|
63 | styles: defaultStyles
|
64 | });
|
65 |
|
66 | propsChanged = true;
|
67 | styles = defaultStyles;
|
68 | } else {
|
69 | styles = {};
|
70 | }
|
71 |
|
72 | var renderResult = _Component.prototype.render.call(this);
|
73 |
|
74 | if (propsChanged) {
|
75 | delete this.props.styles;
|
76 | }
|
77 |
|
78 | if (renderResult) {
|
79 | return (0, _linkClass2.default)(renderResult, styles, options);
|
80 | }
|
81 |
|
82 | return _react2.default.createElement('noscript');
|
83 | };
|
84 |
|
85 | return WrappedComponent;
|
86 | }(Component);
|
87 |
|
88 | return (0, _hoistNonReactStatics2.default)(WrappedComponent, Component);
|
89 | };
|
90 |
|
91 | module.exports = exports['default']; |
\ | No newline at end of file |