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

Function updateSegmentGroup

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

Source from the content-addressed store, hash-verified

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

Callers 2

Calls 4

prefixedWithFunction · 0.85
createNewSegmentGroupFunction · 0.85
hasChildrenMethod · 0.45

Tested by

no test coverage detected