UNPKG

react-render-function

Version:
131 lines (100 loc) 5.02 kB
'use strict'; var React = require('react'); /** * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * */ function makeEmptyFunction(arg) { return function () { return arg; }; } /** * This function accepts and discards inputs; it has no side effects. This is * primarily useful idiomatically for overridable function endpoints which * always need to be callable, since JS lacks a null-call idiom ala Cocoa. */ var emptyFunction = function emptyFunction() {}; emptyFunction.thatReturns = makeEmptyFunction; emptyFunction.thatReturnsFalse = makeEmptyFunction(false); emptyFunction.thatReturnsTrue = makeEmptyFunction(true); emptyFunction.thatReturnsNull = makeEmptyFunction(null); emptyFunction.thatReturnsThis = function () { return this; }; emptyFunction.thatReturnsArgument = function (arg) { return arg; }; var emptyFunction_1 = emptyFunction; /** * Similar to invariant but only logs a warning if the condition is not met. * This can be used to log issues in development environments in critical * paths. Removing the logging code for production environments will keep the * same logic and follow the same code paths. */ var warning = emptyFunction_1; if (process.env.NODE_ENV !== 'production') { var printWarning = function printWarning(format) { for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } var argIndex = 0; var message = 'Warning: ' + format.replace(/%s/g, function () { return args[argIndex++]; }); if (typeof console !== 'undefined') { console.error(message); } try { // --- Welcome to debugging React --- // This error was thrown as a convenience so that you can use this stack // to find the callsite that caused this warning to fire. throw new Error(message); } catch (x) {} }; warning = function warning(condition, format) { if (format === undefined) { throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); } if (format.indexOf('Failed Composite propType: ') === 0) { return; // Ignore CompositeComponent proptype check. } if (!condition) { for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { args[_key2 - 2] = arguments[_key2]; } printWarning.apply(undefined, [format].concat(args)); } }; } var warning_1 = warning; var functionTag = '[object Function]'; var isFunction = function isFunction(value) { return typeof value === 'function' || Object.prototype.toString.call(value) === functionTag; }; var index = (function (ownProps, childProps) { var render = ownProps.render, component = ownProps.component, children = ownProps.children; process.env.NODE_ENV !== 'production' ? warning_1(!(component && render), 'You should not use <Parent component={Child}> and <Parent render={() => <Child />}> in the same <Parent> component. \n only <Parent component={Child}> will be used') : void 0; process.env.NODE_ENV !== 'production' ? warning_1(!(component && children), 'You should not use <Parent component={Child}> and <Parent>{() => <Child />}</Parent> in the same <Parent> component. \n only <Parent component={Child}> will be used') : void 0; process.env.NODE_ENV !== 'production' ? warning_1(!(render && children), 'You should not use <Parent render={() => <Child />}> and <Parent>{() => <Child />}</Parent> in the same <Parent> component. \n only <Parent render={() => <Child />}> will be used') : void 0; process.env.NODE_ENV !== 'production' ? warning_1(!(component && render && children), 'You should not use <Parent component={Child}> , <Parent render={() => <Child />}> and <Parent>{() => <Child />}</Parent>\n in the same <Parent> component. Only <Parent component={Child}> will be used') : void 0; process.env.NODE_ENV !== 'production' ? warning_1(!!(render || children || component), 'You should atleast provide either \n a component injection: <Parent component={Child}>\n a render prop : <Parent render={() => <Child />}>\n or a child as a function: <Parent>{() => <Child />}</Parent>') : void 0; process.env.NODE_ENV !== 'production' ? warning_1(!!(children || component || !render || isFunction(render)), 'render should be a function: <Parent render={() => <Child />} />') : void 0; process.env.NODE_ENV !== 'production' ? warning_1(!!(render || component || !children || isFunction(children)), 'child should be a function: <Parent>{() => <Child />}</Parent>') : void 0; if (component) { return React.createElement(component, childProps); } if (render && isFunction(render)) { return render(childProps); } if (children && isFunction(children)) { return children(childProps); } }); module.exports = index;