angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.28k stars 6.71k forks source link

Add guidelines regarding when an @Output() emits #8675

Open andrewseguin opened 6 years ago

andrewseguin commented 6 years ago

Opening this issue for a discussion regarding when components emit a new event on their stream indicating that their state has changed.

Some components only emit changes when a user interacts with them (e.g. MatPaginator) but do not emit when a programmatic change has occurred. When listening for changes, it may be irrelevant why a value has been changed. E.g. the data source does not care if the page index changes due to a programmatic change or through an Input().

On the other hand, some components may only want to listen to changes made by users and not programmatic ones, especially if it is the listener who made the change.

Any opinions are welcome here

willshowell commented 6 years ago

FWIW isUserInput has been valuable to me in the past

https://github.com/angular/material2/blob/741378a3f257f5e2f6247bb0dec57a8649f2e82e/src/lib/core/option/option.ts#L33-L36

https://github.com/angular/material2/blob/741378a3f257f5e2f6247bb0dec57a8649f2e82e/src/lib/chips/chip.ts#L30-L33

I could imagine something similar in page events.