-
Notifications
You must be signed in to change notification settings - Fork 0
/
lifecycle.js
60 lines (41 loc) · 1.77 KB
/
lifecycle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = require("react");
var _createFactory = _interopRequireDefault(require("./utils/createFactory"));
var _setDisplayName = _interopRequireDefault(require("./setDisplayName"));
var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName"));
/* eslint-disable no-console */
var lifecycle = function lifecycle(spec) {
return function (BaseComponent) {
var factory = (0, _createFactory.default)(BaseComponent);
if (process.env.NODE_ENV !== 'production' && spec.hasOwnProperty('render')) {
console.error('lifecycle() does not support the render method; its behavior is to ' + 'pass all props and state to the base component.');
}
var Lifecycle =
/*#__PURE__*/
function (_Component) {
(0, _inheritsLoose2.default)(Lifecycle, _Component);
function Lifecycle() {
return _Component.apply(this, arguments) || this;
}
var _proto = Lifecycle.prototype;
_proto.render = function render() {
return factory((0, _extends2.default)({}, this.props, this.state));
};
return Lifecycle;
}(_react.Component);
Object.keys(spec).forEach(function (hook) {
return Lifecycle.prototype[hook] = spec[hook];
});
if (process.env.NODE_ENV !== 'production') {
return (0, _setDisplayName.default)((0, _wrapDisplayName.default)(BaseComponent, 'lifecycle'))(Lifecycle);
}
return Lifecycle;
};
};
var _default = lifecycle;
exports.default = _default;