MCPcopy Create free account
hub / github.com/angular/angular / createNewSegmentGroup

Function createNewSegmentGroup

packages/router/src/create_url_tree.ts:515–549  ·  view source on GitHub ↗
(
  segmentGroup: UrlSegmentGroup,
  startIndex: number,
  commands: readonly any[],
)

Source from the content-addressed store, hash-verified

513}
514
515function createNewSegmentGroup(
516 segmentGroup: UrlSegmentGroup,
517 startIndex: number,
518 commands: readonly any[],
519): UrlSegmentGroup {
520 const paths = segmentGroup.segments.slice(0, startIndex);
521
522 let i = 0;
523 while (i < commands.length) {
524 const command = commands[i];
525 if (isCommandWithOutlets(command)) {
526 const children = createNewSegmentChildren(command.outlets);
527 return new UrlSegmentGroup(paths, children);
528 }
529
530 // if we start with an object literal, we need to reuse the path part from the segment
531 if (i === 0 && isMatrixParams(commands[0])) {
532 const p = segmentGroup.segments[startIndex];
533 paths.push(new UrlSegment(p.path, stringify(commands[0])));
534 i++;
535 continue;
536 }
537
538 const curr = isCommandWithOutlets(command) ? command.outlets[PRIMARY_OUTLET] : `${command}`;
539 const next = i < commands.length - 1 ? commands[i + 1] : null;
540 if (curr && next && isMatrixParams(next)) {
541 paths.push(new UrlSegment(curr, stringify(next)));
542 i += 2;
543 } else {
544 paths.push(new UrlSegment(curr, {}));
545 i++;
546 }
547 }
548 return new UrlSegmentGroup(paths, {});
549}
550
551function createNewSegmentChildren(outlets: {[name: string]: readonly unknown[] | string}): {
552 [outlet: string]: UrlSegmentGroup;

Callers 2

updateSegmentGroupFunction · 0.85
createNewSegmentChildrenFunction · 0.85

Calls 6

isCommandWithOutletsFunction · 0.85
createNewSegmentChildrenFunction · 0.85
isMatrixParamsFunction · 0.85
stringifyFunction · 0.70
sliceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected