Skip to content
Closed
Next Next commit
refactor(router): Use for...of rather than mapChildrenIntoArray helper
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.
  • Loading branch information
atscott committed Dec 11, 2020
commit 6c47ec0f5d320dab02b4d54660a91090e9ab4c44
7 changes: 5 additions & 2 deletions packages/router/src/recognize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ class Recognizer {

processChildren(config: Route[], segmentGroup: UrlSegmentGroup):
TreeNode<ActivatedRouteSnapshot>[] {
const children = mapChildrenIntoArray(
segmentGroup, (child, childOutlet) => this.processSegmentGroup(config, child, childOutlet));
const children: Array<TreeNode<ActivatedRouteSnapshot>> = [];
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;
Expand Down