Skip to content

Commit 9efdd1e

Browse files
ammarnajjarcrisbeto
authored andcommitted
docs(material/autocomplete): use single map instead of two maps in a row (#25167)
* docs(material/autocomplete): use single map instead of two maps in a row The example code is highly trusted and sometimes taken as is (copy-paste), so it is important to have it optimized if possible. Each map means an iteration over the array items. By using single map, an iteration is saved, and an approximate performance of about 38% is won. * docs(material/autocomplete): add trailing comma (cherry picked from commit 8ca012f)
1 parent 422f69d commit 9efdd1e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/components-examples/material/autocomplete/autocomplete-display/autocomplete-display-example.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ export class AutocompleteDisplayExample implements OnInit {
2323
ngOnInit() {
2424
this.filteredOptions = this.myControl.valueChanges.pipe(
2525
startWith(''),
26-
map(value => (typeof value === 'string' ? value : value?.name)),
27-
map(name => (name ? this._filter(name) : this.options.slice())),
26+
map(value => {
27+
const name = typeof value === 'string' ? value : value?.name;
28+
return name ? this._filter(name as string) : this.options.slice();
29+
}),
2830
);
2931
}
3032

0 commit comments

Comments
 (0)