From 9efdd1eba0994a367ba3a363700218a8b94009a1 Mon Sep 17 00:00:00 2001 From: Ammar Najjar Date: Mon, 27 Jun 2022 13:59:58 +0200 Subject: [PATCH] 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 8ca012fdf63a540c0364d6acecd1d378f60f444e) --- .../autocomplete-display/autocomplete-display-example.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components-examples/material/autocomplete/autocomplete-display/autocomplete-display-example.ts b/src/components-examples/material/autocomplete/autocomplete-display/autocomplete-display-example.ts index faefb50d0448..ec7efae4b0cb 100644 --- a/src/components-examples/material/autocomplete/autocomplete-display/autocomplete-display-example.ts +++ b/src/components-examples/material/autocomplete/autocomplete-display/autocomplete-display-example.ts @@ -23,8 +23,10 @@ export class AutocompleteDisplayExample implements OnInit { ngOnInit() { this.filteredOptions = this.myControl.valueChanges.pipe( startWith(''), - map(value => (typeof value === 'string' ? value : value?.name)), - map(name => (name ? this._filter(name) : this.options.slice())), + map(value => { + const name = typeof value === 'string' ? value : value?.name; + return name ? this._filter(name as string) : this.options.slice(); + }), ); }