Skip to content

Commit

Permalink
docs(material/autocomplete): use single map instead of two maps in a …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
ammarnajjar authored and crisbeto committed Jun 27, 2022
1 parent 422f69d commit 9efdd1e
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}),
);
}

Expand Down

0 comments on commit 9efdd1e

Please sign in to comment.