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

Function tree

packages/router/src/create_url_tree.ts:182–217  ·  view source on GitHub ↗
(
  oldRoot: UrlSegmentGroup,
  oldSegmentGroup: UrlSegmentGroup,
  newSegmentGroup: UrlSegmentGroup,
  queryParams: Params | null,
  fragment: string | null,
  urlSerializer: UrlSerializer,
)

Source from the content-addressed store, hash-verified

180}
181
182function tree(
183 oldRoot: UrlSegmentGroup,
184 oldSegmentGroup: UrlSegmentGroup,
185 newSegmentGroup: UrlSegmentGroup,
186 queryParams: Params | null,
187 fragment: string | null,
188 urlSerializer: UrlSerializer,
189): UrlTree {
190 const qp: Params = {};
191 for (const [key, value] of Object.entries(queryParams ?? {})) {
192 if (value === null || value === undefined) {
193 continue;
194 }
195 // This retains old behavior where each item in the array was stringified individually This
196 // helps remove special-case handling for empty and single-item arrays where the default
197 // serializer removes empty arrays when serialized then parsed or converts them to non-arrays
198 // for single-item arrays. Changing this could have breaking change implications. Prior code
199 // always returned arrays of strings for array inputs so tests, applications, serializers,
200 // etc. may only be set up to handle string arrays. We could consider changing this in the
201 // future to serialize the entire array as a single value. For now, this feels safer and is
202 // at least a step in the right direction.
203 qp[key] = Array.isArray(value)
204 ? value.map((v) => normalizeQueryParams(key, v, urlSerializer))
205 : normalizeQueryParams(key, value, urlSerializer);
206 }
207
208 let rootCandidate: UrlSegmentGroup;
209 if (oldRoot === oldSegmentGroup) {
210 rootCandidate = newSegmentGroup;
211 } else {
212 rootCandidate = replaceSegment(oldRoot, oldSegmentGroup, newSegmentGroup);
213 }
214
215 const newRoot = createRoot(squashSegmentGroup(rootCandidate));
216 return new UrlTree(newRoot, qp, fragment);
217}
218
219/**
220 * Replaces the `oldSegment` which is located in some child of the `current` with the `newSegment`.

Callers 1

Calls 7

createRootFunction · 0.90
squashSegmentGroupFunction · 0.90
replaceSegmentFunction · 0.85
isArrayMethod · 0.80
mapMethod · 0.80
normalizeQueryParamsFunction · 0.70
entriesMethod · 0.45

Tested by

no test coverage detected