From 707c85484bf37848de9666bd475a690f82c22eaf Mon Sep 17 00:00:00 2001 From: jbone123 <1082388+jbone123@user.noreply.gitee.com> Date: Wed, 8 Apr 2020 00:00:20 +0800 Subject: [PATCH 1/3] add LICENSE. --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9aeae51 --- /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. -- Gitee From 18916a377223e982a20cdcca5948d64c904d83da Mon Sep 17 00:00:00 2001 From: jbone Date: Wed, 8 Apr 2020 10:33:26 +0800 Subject: [PATCH 2/3] flat --- src/react/ReactChildren.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/react/ReactChildren.js b/src/react/ReactChildren.js index bbc07d8..b60cf86 100644 --- a/src/react/ReactChildren.js +++ b/src/react/ReactChildren.js @@ -1,8 +1,29 @@ 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++; + } + }); + } + if (Array.isArray(children)) { + flat(children); + } + return arr; } -export { - mapChildren as map, -}; \ No newline at end of file +export { mapChildren as map }; -- Gitee From 3566bce14de8395aad1c76d8f9e16aaa0f8a975d Mon Sep 17 00:00:00 2001 From: jbone Date: Wed, 8 Apr 2020 12:01:50 +0800 Subject: [PATCH 3/3] flat --- src/react/ReactChildren.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/react/ReactChildren.js b/src/react/ReactChildren.js index b60cf86..1cf994b 100644 --- a/src/react/ReactChildren.js +++ b/src/react/ReactChildren.js @@ -18,6 +18,7 @@ function mapChildren(children, func, context) { } index++; } + return arr; }); } if (Array.isArray(children)) { -- Gitee