UNPKG

4.25 kBJavaScriptView Raw
1'use strict';
2
3var _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; }; }();
4
5var _rax = require('rax');
6
7var _reactDeepForceUpdate = require('react-deep-force-update');
8
9var _reactDeepForceUpdate2 = _interopRequireDefault(_reactDeepForceUpdate);
10
11var _reactChildren = require('react-children');
12
13var _reactChildren2 = _interopRequireDefault(_reactChildren);
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
17function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
19function _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; }
20
21function _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; }
22
23var AppContainer = function (_Component) {
24 _inherits(AppContainer, _Component);
25
26 function AppContainer(props) {
27 _classCallCheck(this, AppContainer);
28
29 var _this = _possibleConstructorReturn(this, (AppContainer.__proto__ || Object.getPrototypeOf(AppContainer)).call(this, props));
30
31 _this.state = { error: null };
32 return _this;
33 }
34
35 _createClass(AppContainer, [{
36 key: 'componentDidMount',
37 value: function componentDidMount() {
38 if (typeof __RAX_HOT_LOADER__ === 'undefined') {
39 console.error('Rax Hot Loader: It appears that "rax-hot-loader/patch" ' + 'did not run immediately before the app started. Make sure that it ' + 'runs before any other code. For example, if you use Webpack, ' + 'you can add "rax-hot-loader/patch" as the very first item to the ' + '"entry" array in its config. Alternatively, you can add ' + 'require("rax-hot-loader/patch") as the very first line ' + 'in the application code, before any other imports.');
40 }
41 }
42 }, {
43 key: 'componentWillReceiveProps',
44 value: function componentWillReceiveProps() {
45 // Hot reload is happening.
46 // Retry rendering!
47 this.setState({
48 error: null
49 });
50 // Force-update the whole tree, including
51 // components that refuse to update.
52 (0, _reactDeepForceUpdate2.default)(this);
53 }
54
55 // This hook is going to become official in React 15.x.
56 // In 15.0, it only catches errors on initial mount.
57 // Later it will work for updates as well:
58 // https://github.com/facebook/react/pull/6020
59
60 }, {
61 key: 'unstable_handleError',
62 value: function unstable_handleError(error) {
63 // eslint-disable-line camelcase
64 this.setState({
65 error: error
66 });
67 }
68 }, {
69 key: 'render',
70 value: function render() {
71 var error = this.state.error;
72
73 if (error) {
74 console.log(error);
75 return false;
76 }
77
78 return _reactChildren2.default.only(this.props.children);
79 }
80 }]);
81
82 return AppContainer;
83}(_rax.Component);
84
85AppContainer.propTypes = {
86 children: function children(props) {
87 if (_reactChildren2.default.count(props.children) !== 1) {
88 return new Error('Invalid prop "children" supplied to AppContainer. ' + 'Expected a single React element with your app’s root component, e.g. <App />.');
89 }
90
91 return undefined;
92 }
93};
94
95module.exports = AppContainer;
\No newline at end of file