MCPcopy Index your code
hub / github.com/angular/components / _computeRenderingData

Method _computeRenderingData

src/cdk/tree/tree.ts:1055–1115  ·  view source on GitHub ↗

* Converts children for certain tree configurations. * * This also computes parent, level, and group data.

(
    nodes: readonly T[],
    nodeType: 'flat' | 'nested',
  )

Source from the content-addressed store, hash-verified

1053 * This also computes parent, level, and group data.
1054 */
1055 private _computeRenderingData(
1056 nodes: readonly T[],
1057 nodeType: 'flat' | 'nested',
1058 ): Observable<{
1059 renderNodes: readonly T[];
1060 flattenedNodes: readonly T[];
1061 }> {
1062 // The only situations where we have to convert children types is when
1063 // they're mismatched; i.e. if the tree is using a childrenAccessor and the
1064 // nodes are flat, or if the tree is using a levelAccessor and the nodes are
1065 // nested.
1066 if (this.childrenAccessor && nodeType === 'flat') {
1067 // clear previously generated data so we don't keep end up retaining data overtime causing
1068 // memory leaks.
1069 this._clearPreviousCache();
1070 // This flattens children into a single array.
1071 this._ariaSets.set(null, [...nodes]);
1072 return this._flattenNestedNodesWithExpansion(nodes).pipe(
1073 map(flattenedNodes => ({
1074 renderNodes: flattenedNodes,
1075 flattenedNodes,
1076 })),
1077 );
1078 } else if (this.levelAccessor && nodeType === 'nested') {
1079 // In the nested case, we only look for root nodes. The CdkNestedNode
1080 // itself will handle rendering each individual node's children.
1081 const levelAccessor = this.levelAccessor;
1082 return observableOf(nodes.filter(node => levelAccessor(node) === 0)).pipe(
1083 map(rootNodes => ({
1084 renderNodes: rootNodes,
1085 flattenedNodes: nodes,
1086 })),
1087 tap(({flattenedNodes}) => {
1088 this._calculateParents(flattenedNodes);
1089 }),
1090 );
1091 } else if (nodeType === 'flat') {
1092 // In the case of a TreeControl, we know that the node type matches up
1093 // with the TreeControl, and so no conversions are necessary. Otherwise,
1094 // we've already confirmed that the data model matches up with the
1095 // desired node type here.
1096 return observableOf({renderNodes: nodes, flattenedNodes: nodes}).pipe(
1097 tap(({flattenedNodes}) => {
1098 this._calculateParents(flattenedNodes);
1099 }),
1100 );
1101 } else {
1102 // clear previously generated data so we don't keep end up retaining data overtime causing
1103 // memory leaks.
1104 this._clearPreviousCache();
1105 // For nested nodes, we still need to perform the node flattening in order
1106 // to maintain our caches for various tree operations.
1107 this._ariaSets.set(null, [...nodes]);
1108 return this._flattenNestedNodesWithExpansion(nodes).pipe(
1109 map(flattenedNodes => ({
1110 renderNodes: nodes,
1111 flattenedNodes,
1112 })),

Callers 1

_getRenderDataMethod · 0.95

Calls 5

_clearPreviousCacheMethod · 0.95
_calculateParentsMethod · 0.95
setMethod · 0.80
filterMethod · 0.45

Tested by

no test coverage detected