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

Method transform

packages/common/src/pipes/keyvalue_pipe.ts:118–147  ·  view source on GitHub ↗
(
    input: undefined | null | {[key: string]: V; [key: number]: V} | ReadonlyMap<K, V>,
    compareFn: ((a: KeyValue<K, V>, b: KeyValue<K, V>) => number) | null = defaultComparator,
  )

Source from the content-addressed store, hash-verified

116 ): T extends object ? Array<KeyValue<keyof T, T[keyof T]>> : null;
117
118 transform<K, V>(
119 input: undefined | null | {[key: string]: V; [key: number]: V} | ReadonlyMap<K, V>,
120 compareFn: ((a: KeyValue<K, V>, b: KeyValue<K, V>) => number) | null = defaultComparator,
121 ): Array<KeyValue<K, V>> | null {
122 ngDevMode && warnIfSignal('KeyValuePipe', input);
123
124 if (!input || (!(input instanceof Map) && typeof input !== 'object')) {
125 return null;
126 }
127
128 // make a differ for whatever type we've been passed in
129 this.differ ??= this.differs.find(input).create();
130
131 const differChanges: KeyValueChanges<K, V> | null = this.differ.diff(input as any);
132 const compareFnChanged = compareFn !== this.compareFn;
133
134 if (differChanges) {
135 this.keyValues = [];
136 differChanges.forEachItem((r: KeyValueChangeRecord<K, V>) => {
137 this.keyValues.push(makeKeyValuePair(r.key, r.currentValue!));
138 });
139 }
140 if (differChanges || compareFnChanged) {
141 if (compareFn) {
142 this.keyValues.sort(compareFn);
143 }
144 this.compareFn = compareFn;
145 }
146 return this.keyValues;
147 }
148}
149
150export function defaultComparator<K, V>(

Callers

nothing calls this directly

Calls 7

warnIfSignalFunction · 0.90
makeKeyValuePairFunction · 0.85
createMethod · 0.65
diffMethod · 0.65
forEachItemMethod · 0.65
findMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected