angular / angular/components

MdAutocompleteTrigger writeValue is asynchronous

Open
#3,250 1 comment 4 reactions 0 assignees View on GitHub
area: material/autocomplete P3
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

#### Bug, feature request, or proposal:
Request for change (RFC)

#### What is the expected behavior?
The MdAutocompleteTrigger writeValue ValueAccesor method should be synchronous.

#### What is the current behavior?
The MdAutocompleteTrigger writeValue ValueAccesor method is asynchronous.

#### What are the steps to reproduce?
Simply implement the autocomplete and try to detect a change being reflected within the view upon updating the `formControl` through `setValue`.
Doing this requires a `setTimeout` coupled with wrapping the body of the `it` statement with `async(() => { ... })` when writing unit tests. If you wish to detect the change being relayed to the input `value`.

This is caused by the fact that (I assume) the writeValue wraps the `_setTriggerValue` method in a `Promise.resolve(...)`: https://github.com/angular/material2/blob/master/src/lib/autocomplete/autocomplete-trigger.ts#L179

#### What is the use-case or motivation for changing an existing behavior?
The motivation for this RFC is the fact that it complicates testing. If their are valid reasons to make the autocomplete trigger asynchronous then that's fine, but the documentation should reflect this fact.

#### Which versions of Angular, Material, OS, browsers are affected?
2.0.0-beta.2

Contributor guide

Open the contributing guide

Research direction

Start with src/lib/autocomplete/autocomplete-trigger.ts, especially writeValue and the Promise.resolve call referenced in the issue. Reproduce the behavior by updating a formControl with setValue and checking when the input value changes. Done means the requested synchronous behavior is resolved or the asynchronous behavior is explicitly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.