-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Why does handleExtendsNodes use the Array.reduce function instead of Array.map? As far as I can see it's always a direct transformation, the purpose of Array.map.
Also, shouldn't the line m = m.concat(...) just be m.push(...)?
Using map and push instead of concat would simplify the code from this (I removed irrelevant lines):
function handleExtendsNodes (tree, options, ctx) {
return tree.reduce((m, node) => {
if (node.name !== 'extends') {
if (Array.isArray(node.content)) {
node.content = handleExtendsNodes(node.content, options, ctx)
m.push(node)
} else {
m.push(node)
}
return m
}
// ... snip ...
m = m.concat(mergeExtendsAndLayout(layoutTree, handleExtendsNodes(node.content, options, ctx), ctx))
return m
}, [])
}to this:
function handleExtendsNodes (tree, options, ctx) {
return tree.map(node => {
if (node.name !== 'extends') {
if (Array.isArray(node.content)) {
node.content = handleExtendsNodes(node.content, options, ctx)
}
return node
}
// ... snip ...
return mergeExtendsAndLayout(layoutTree, handleExtendsNodes(node.content, options, ctx), ctx)
})
}I haven't tested this code so I'm not 100% sure it works as intended, but I don't see any reason why there's the need for reduce. I might however be missing something (probably very obvious), hence the question.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels