From 77f47da0166b8d0b5a209e5499f3d3172b236d62 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Wed, 25 Nov 2020 17:19:43 -0800 Subject: [PATCH] refactor(router): Use for...of rather than `mapChildrenIntoArray` helper (#40029) When stepping through the `recognize` algorithm, it is much easier to follow when using a simple `for...of` rather than the helper `mapChildrenIntoArray` with the passed closure. The only special thing that `mapChildrenIntoArray` does is ensure the primary route appears first. This change will have no affect on the result because `processChildren` later calls `sortActivatedRouteSnapshots`, which does the same thing. PR Close #40029 --- packages/router/src/recognize.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/router/src/recognize.ts b/packages/router/src/recognize.ts index 20cf038216..4c392a2fbe 100644 --- a/packages/router/src/recognize.ts +++ b/packages/router/src/recognize.ts @@ -79,8 +79,11 @@ class Recognizer { processChildren(config: Route[], segmentGroup: UrlSegmentGroup): TreeNode[] { - const children = mapChildrenIntoArray( - segmentGroup, (child, childOutlet) => this.processSegmentGroup(config, child, childOutlet)); + const children: Array> = []; + for (const childOutlet of Object.keys(segmentGroup.children)) { + const child = segmentGroup.children[childOutlet]; + children.push(...this.processSegmentGroup(config, child, childOutlet)); + } checkOutletNameUniqueness(children); sortActivatedRouteSnapshots(children); return children;