Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cdk/layout): support readonly arrays for public methods #20252

Merged
merged 2 commits into from Aug 19, 2020

Conversation

rafaelss95
Copy link
Contributor

This PR add support for readonly string[] for methods isMatched and observe as they doesn't accept it currently.

Also, I've refactored it a bit to remove some unnecessary type annotations.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 9, 2020
return stateObservable.pipe(map(breakpointStates => {
return breakpointStates.reduce((previousState, {matches, query}) => ({
...previousState,
breakpoints: {...previousState.breakpoints, [query]: matches},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is shorter, but less efficient since it transpiles to two Object.assign calls. I'm guessing that's why it was previously written with a forEach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, reverted.

@@ -71,7 +71,7 @@ export class BreakpointObserver implements OnDestroy {
* @param value One or more media queries to check.
* @returns A stream of matches for the given queries.
*/
observe(value: string | string[]): Observable<BreakpointState> {
observe(value: string | readonly string[]): Observable<BreakpointState> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be ReadonlyArray<string>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadonlyArray<string> and readonly string[] have exactly the same meaning. I can adjust if the ReadonlyArray<> style is more adopted in the repo.

PS: It would be nice to pick one of the styles and use it consistently. In angular repo someone created an issue relating this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do prefer readonly string[] myself

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -71,7 +71,7 @@ export class BreakpointObserver implements OnDestroy {
* @param value One or more media queries to check.
* @returns A stream of matches for the given queries.
*/
observe(value: string | string[]): Observable<BreakpointState> {
observe(value: string | readonly string[]): Observable<BreakpointState> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do prefer readonly string[] myself

@jelbourn jelbourn added action: merge The PR is ready for merge by the caretaker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Aug 10, 2020
@wagnermaciel wagnermaciel merged commit e3699dc into angular:master Aug 19, 2020
wagnermaciel pushed a commit that referenced this pull request Aug 19, 2020
* fix(cdk/layout): support readonly arrays for public methods

* refactor(cdk/layout): remove unnecessary type annotations

(cherry picked from commit e3699dc)
@rafaelss95 rafaelss95 deleted the fix/cdk/layout branch August 19, 2020 01:36
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants