UNPKG

@saber2pr/react

Version:

react in Typescript.

45 lines (44 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /* * @Author: saber2pr * @Date: 2019-12-07 15:25:38 * @Last Modified by: saber2pr * @Last Modified time: 2019-12-08 11:01:04 */ var ReactTypes_1 = require("../shared/ReactTypes"); var toTextFiber = function (nodeValue) { return ({ tag: "#text", $$typeof: ReactTypes_1.NodeType.Text, props: { nodeValue: nodeValue } }); }; // flat polyfill var flat = function (arr) { var _a; return (_a = Array.prototype).concat.apply(_a, arr); }; var flat2 = function (arr) { return flat(flat(arr)); }; var Children; (function (Children) { Children.toArray = function () { var children = []; for (var _i = 0; _i < arguments.length; _i++) { children[_i] = arguments[_i]; } return flat2(children).reduce(function (acc, ch) { // `if render` get false or undefind, ignore it if (ch === false || ch === undefined) return acc; // to text node if (typeof ch === "number") { return acc.concat(toTextFiber(ch)); } if (typeof ch === "string") { return acc.concat(toTextFiber(ch)); } // collect object return acc.concat(ch); }, []); }; })(Children || (Children = {})); exports.Children = Children;