UNPKG

1.42 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6
7function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
8
9var _react = require('react');
10
11var _react2 = _interopRequireDefault(_react);
12
13var _invariant = require('invariant');
14
15var _invariant2 = _interopRequireDefault(_invariant);
16
17var ContextWrapper = _react2['default'].createClass({
18 displayName: 'ThunderCatsContextWrapper',
19 propTypes: {
20 cat: _react2['default'].PropTypes.object.isRequired,
21 children: _react2['default'].PropTypes.element.isRequired
22 },
23
24 childContextTypes: {
25 cat: _react2['default'].PropTypes.object.isRequired
26 },
27
28 getChildContext: function getChildContext() {
29 return {
30 cat: this.props.cat
31 };
32 },
33
34 render: function render() {
35 return _react.Children.only(this.props.children);
36 }
37});
38
39// wrap a component in this context wrapper
40/* eslint-disable react/no-multi-comp, react/display-name */
41ContextWrapper.wrap = function wrap(element, cat) {
42 (0, _invariant2['default'])(_react2['default'].isValidElement(element), 'ContextWrapper wrap expects a valid React element');
43
44 (0, _invariant2['default'])(typeof cat === 'object', 'ContextWrapper expects an instance of Cat');
45
46 return _react2['default'].createElement(ContextWrapper, { cat: cat }, element);
47};
48
49exports['default'] = ContextWrapper;
50module.exports = exports['default'];
\No newline at end of file