UNPKG

3.59 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.reactStory = reactStory;
7exports.default = void 0;
8
9var _react = _interopRequireDefault(require("react"));
10
11var _propTypes = _interopRequireDefault(require("prop-types"));
12
13function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
16
17function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
19function _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); } }
20
21function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
22
23function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
24
25function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
27function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
29function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
30
31function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
32
33var ReactDecorator =
34/*#__PURE__*/
35function (_React$Component) {
36 _inherits(ReactDecorator, _React$Component);
37
38 function ReactDecorator(props) {
39 var _this;
40
41 _classCallCheck(this, ReactDecorator);
42
43 _this = _possibleConstructorReturn(this, _getPrototypeOf(ReactDecorator).call(this, props));
44
45 _this.props.onMount();
46
47 return _this;
48 }
49
50 _createClass(ReactDecorator, [{
51 key: "componentWillUnmount",
52 value: function componentWillUnmount() {
53 this.props.onUnMount();
54 }
55 }, {
56 key: "render",
57 value: function render() {
58 return this.props.story;
59 }
60 }]);
61
62 return ReactDecorator;
63}(_react.default.Component);
64
65ReactDecorator.propTypes = {
66 story: _propTypes.default.node.isRequired,
67 onMount: _propTypes.default.func.isRequired,
68 onUnMount: _propTypes.default.func.isRequired
69};
70var _default = ReactDecorator;
71exports.default = _default;
72
73function reactStory(story, onMount, onUnMount) {
74 return _react.default.createElement(ReactDecorator, {
75 story: story,
76 onMount: onMount,
77 onUnMount: onUnMount
78 });
79}
\No newline at end of file