diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..9aeae51907afe13d812c22651fb84bc0855fe559 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 jbone123 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/react/ReactChildren.js b/src/react/ReactChildren.js index bbc07d81edaad3705a3dca0942e1cbc01bff2624..1cf994b1b62812a5fd751f496fda6c00b5eb40bb 100644 --- a/src/react/ReactChildren.js +++ b/src/react/ReactChildren.js @@ -1,8 +1,30 @@ function mapChildren(children, func, context) { - //TODO实现此mapChildren方法 + //TODO实现此mapChildren方法 + // return children; + let index = 0; + let arr = []; + if (children == null) { return children; + } + function flat(children) { + children.map((item) => { + if (Array.isArray(item)) { + flat(item); + } else { + let funcEle = func.call(context, item, index); + console.log(funcEle, "funcEle"); + if (Array.isArray(funcEle)) { + arr = arr.concat(funcEle); + } + index++; + } + return arr; + }); + } + if (Array.isArray(children)) { + flat(children); + } + return arr; } -export { - mapChildren as map, -}; \ No newline at end of file +export { mapChildren as map };