88264[TASK] Improve code-style for JS `Array.prototype.reduce`
Commit message
Review
-
Code review CR 0
-
Verified V -1
- core-ci -1 CI
Issues 1
Files 4
Review log 79
-
Ayke Halder uploaded patch set 1 02/18/25, 14:19
-
core-ci voted on patch set 1 V +1 02/18/25, 14:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/74319
-
Ayke Halder commented on patch set 1 02/18/25, 14:41
-
Benjamin Franzke commented on patch set 1 CR -1 02/18/25, 16:38
I do not agree. Every developer should know that local variable scopes overwrite outside scope. The term accumulator does not help, it's like using type-suffixes/prefixes in the old days… like `fooArray`, or `aFoo`. We can call it `enhancedNodes`, if that helps.tree.ts:508I'm really not a fan of premature optimization. Why this bold statement? a) we're dealing with small chunks of data here (it's not the entire tree, only the subtree that has been loaded from the server, that is being enhanced here) b) `[...nodes, node]` allows the browser to apply optimizations, since it could GC `nodes`. This is something that is actively being worked on, see https://v8.dev/blog/spread-elements#conclusion c) Combining functional programming with mutable structures makes this code even harder to understand, it's better to avoid mutations in transformation pipelines.tree.ts:513ReplyIntention was to search in the already enhanced nodes (current code is correct), that means in the accumulator – that's the reason why `.reduce()` instead of `.map()` was used here. Background: nodes processing requires their parents to be processed in order to generate the recursive `__treeIdentifier` -
Ayke Halder commented on patch set 1 02/19/25, 10:56
Reply Unresolved
Unfortunately `enhancedNodes` is also already in use. So neither * const enhancedNodes = **nodes**.reduce((**nodes**, node) => {…})` nor * const **enhancedNodes** = nodes.reduce((**enhancedNodes**, node) => {…}) looks like a nice solution here. To make e.g. ESlint "@typescript-eslint/no-shadow" work, the name must be unique. -
Ayke Halder commented on patch set 1 02/19/25, 11:07
tree.ts:508Reply UnresolvedJust to correctly understand the issue with mutable structs. Is the following example also a mutation, caused by the outside scope variable? Example using `map` instead of `reduce`: ``` const lastParentNodeByDepth: TreeNodeInterface[] = []; const enhancedNodes = nodes.map((node: TreeNodeInterface) => { node = Object.assign({}, this.settings.defaultProperties, node); node.__parents = []; const parentNode = node.depth > 0 ? lastParentNodeByDepth[node.depth - 1] : null; if (parentNode) { node.__parents = [ ...parentNode.__parents, parentNode.identifier ]; } lastParentNodeByDepth[node.depth] = node; return node; } ```tree.ts:513ReplyAcknowledged. -
Benni Mack updated the commit message in patch set 2
CR -1V +104/22/26, 06:30 -
core-ci voted on patch set 2 V -1 04/22/26, 07:00 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/100711
-
Georg Ringer abandoned the change 11/12/26, 21:02
abandoning the issue as no progress + see forge for more
tree.ts:513