[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | var tslib_1 = require("tslib");
|
---|
| 4 | var react_1 = require("react");
|
---|
| 5 | var isReact16Plus = parseInt(react_1.version.substr(0, react_1.version.indexOf('.'))) > 15;
|
---|
| 6 | var isFn = function (fn) { return typeof fn === 'function'; };
|
---|
| 7 | var render = function (props, data) {
|
---|
| 8 | var more = [];
|
---|
| 9 | for (var _i = 2; _i < arguments.length; _i++) {
|
---|
| 10 | more[_i - 2] = arguments[_i];
|
---|
| 11 | }
|
---|
| 12 | if (process.env.NODE_ENV !== 'production') {
|
---|
| 13 | if (typeof props !== 'object') {
|
---|
| 14 | throw new TypeError('renderChildren(props, data) first argument must be a props object.');
|
---|
| 15 | }
|
---|
| 16 | var children_1 = props.children, render_1 = props.render;
|
---|
| 17 | if (isFn(children_1) && isFn(render_1)) {
|
---|
| 18 | console.warn('Both "render" and "children" are specified for in a universal interface component. ' +
|
---|
| 19 | 'Children will be used.');
|
---|
| 20 | console.trace();
|
---|
| 21 | }
|
---|
| 22 | if (typeof data !== 'object') {
|
---|
| 23 | console.warn('Universal component interface normally expects data to be an object, ' +
|
---|
| 24 | ("\"" + typeof data + "\" received."));
|
---|
| 25 | console.trace();
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 | var render = props.render, _a = props.children, children = _a === void 0 ? render : _a, component = props.component, _b = props.comp, comp = _b === void 0 ? component : _b;
|
---|
| 29 | if (isFn(children))
|
---|
| 30 | return children.apply(void 0, tslib_1.__spreadArrays([data], more));
|
---|
| 31 | if (comp) {
|
---|
| 32 | return react_1.createElement(comp, data);
|
---|
| 33 | }
|
---|
| 34 | if (children instanceof Array)
|
---|
| 35 | return isReact16Plus ? children : react_1.createElement.apply(void 0, tslib_1.__spreadArrays(['div', null], children));
|
---|
| 36 | if (children && (children instanceof Object)) {
|
---|
| 37 | if (process.env.NODE_ENV !== 'production') {
|
---|
| 38 | if (!children.type || ((typeof children.type !== 'string') && (typeof children.type !== 'function') && (typeof children.type !== 'symbol'))) {
|
---|
| 39 | console.warn('Universal component interface received object as children, ' +
|
---|
| 40 | 'expected React element, but received unexpected React "type".');
|
---|
| 41 | console.trace();
|
---|
| 42 | }
|
---|
| 43 | if (typeof children.type === 'string')
|
---|
| 44 | return children;
|
---|
| 45 | return react_1.cloneElement(children, Object.assign({}, children.props, data));
|
---|
| 46 | }
|
---|
| 47 | else {
|
---|
| 48 | if (typeof children.type === 'string')
|
---|
| 49 | return children;
|
---|
| 50 | return react_1.cloneElement(children, Object.assign({}, children.props, data));
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | return children || null;
|
---|
| 54 | };
|
---|
| 55 | exports.default = render;
|
---|
| 56 | //# sourceMappingURL=render.js.map |
---|