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

Function updateSegmentGroup

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

Source from the content-addressed store, hash-verified

385}
386
387function updateSegmentGroup(
388 segmentGroup: UrlSegmentGroup | undefined,
389 startIndex: number,
390 commands: readonly any[],
391): UrlSegmentGroup {
392 segmentGroup ??= new UrlSegmentGroup([], {});
393 if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
394 return updateSegmentGroupChildren(segmentGroup, startIndex, commands);
395 }
396
397 const m = prefixedWith(segmentGroup, startIndex, commands);
398 const slicedCommands = commands.slice(m.commandIndex);
399 if (m.match && m.pathIndex < segmentGroup.segments.length) {
400 const g = new UrlSegmentGroup(segmentGroup.segments.slice(0, m.pathIndex), {});
401 g.children[PRIMARY_OUTLET] = new UrlSegmentGroup(
402 segmentGroup.segments.slice(m.pathIndex),
403 segmentGroup.children,
404 );
405 return updateSegmentGroupChildren(g, 0, slicedCommands);
406 } else if (m.match && slicedCommands.length === 0) {
407 return new UrlSegmentGroup(segmentGroup.segments, {});
408 } else if (m.match && !segmentGroup.hasChildren()) {
409 return createNewSegmentGroup(segmentGroup, startIndex, commands);
410 } else if (m.match) {
411 return updateSegmentGroupChildren(segmentGroup, 0, slicedCommands);
412 } else {
413 return createNewSegmentGroup(segmentGroup, startIndex, commands);
414 }
415}
416
417function updateSegmentGroupChildren(
418 segmentGroup: UrlSegmentGroup,

Callers 2

Calls 5

prefixedWithFunction · 0.85
createNewSegmentGroupFunction · 0.85
sliceMethod · 0.65
hasChildrenMethod · 0.45

Tested by

no test coverage detected