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(common): fix immutability for locale_data_api #30397

Closed
wants to merge 1 commit into from
Closed

fix(common): fix immutability for locale_data_api #30397

wants to merge 1 commit into from

Conversation

artem-galas
Copy link
Contributor

@artem-galas artem-galas commented May 10, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Since no new array instance was returned (on getLocaleMonthNames / getLocaleDayNames methods), after manipulation (e.q splice, push) on array it's not possible to get full list of localized days/month.

Issue Number: #27003

What is the new behavior?

Add Array.from to return value from these methods.
Add general tests for both methods (they didn't have any before), and also add tests for testing bugfix

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@artem-galas artem-galas requested review from as code owners May 10, 2019
@ngbot ngbot bot added this to the needsTriage milestone May 10, 2019
@alxhub
Copy link
Contributor

@alxhub alxhub commented May 10, 2019

I think a better change would be to have this API return ReadonlyArray<...>.

@artem-galas
Copy link
Contributor Author

@artem-galas artem-galas commented May 11, 2019

Thanks for your review.
I agree it's better to return ReadonlyArray, in that case we freeze these arrays for manipulations.

@artem-galas
Copy link
Contributor Author

@artem-galas artem-galas commented May 13, 2019

Test are failing with error

Error: Symbol not found for identifier: readonly

I don't have any idea what does it mean.
Could you please give me a piece of advise?

@ocombe
Copy link
Contributor

@ocombe ocombe commented May 13, 2019

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Jul 12, 2020

@artem-galas - would you mind rebasing this on master?

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Jul 12, 2020

Can you also tighten up the commit message a bit so that readers of the changelog will understand more what has changed. Perhaps something more like:

fix(common): mark locale data arrays as readonly

To discourage developers from mutating the arrays returned
from the following methods, their return types have been marked
as readonly.

* `getLocaleDayPeriods()`
* `getLocaleDayNames()`
* `getLocaleMonthNames()`
* `getLocaleEraNames()`

Fixes #27003

BREAKING CHANGE:
The locale data API has been marked as returning readonly arrays, rather
than mutable arrays, since these arrays are shared across calls to the
API. If you were mutating them (e.g. calling `sort()`, `push()`, `splice()`, etc)
then your code will not longer compile. If you need to mutate the array, you
should now take a copy (e.g. by calling `slice()`) and mutate the copy.

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Jul 12, 2020

I just realised that this will probably fail due to the public API change. We will need to update the public API "golden files"...
The CI test failures will say what commands need to be run to do this.

Copy link
Member

@petebacondarwin petebacondarwin left a comment

As this is a breaking change to the public API, it could only land in 11.0.0

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Jul 12, 2020

I think it is worth running a presubmit now to see how many Google projects would be broken by this change.

goldens/public-api/common/common.d.ts Outdated Show resolved Hide resolved
@AndrewKushnir AndrewKushnir removed this from the needsTriage milestone Jul 28, 2020
@AndrewKushnir AndrewKushnir added this to the v11-candidates milestone Jul 28, 2020
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

LGTM 👍

Reviewed-for: fw-core

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Jul 28, 2020

Note to Caretakers: since this is a breaking change, we'd need to run Global presubmit as well once master branch is available for v11 changes.

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Adding LGTM for the public-api group.

Reviewed-for: public-api

Copy link
Contributor

@atscott atscott left a comment

Reviewed-for: public-api

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Sep 9, 2020

Hi @artem-galas, the 10.1.0 version was released last week and master branch is now available for changes that target next major release (v11). Could you please rebase this PR, so that we re-run tests with the current version of master branch? Please let us know (in this thread) once this PR is rebased, so that we re-run tests in Google's codebase. Thank you.

mhevery
mhevery approved these changes Sep 9, 2020
Copy link
Contributor

@mhevery mhevery left a comment

Reviewed-for: fw-core

To discourage developers from mutating the arrays returned
from the following methods, their return types have been marked
as readonly.

* `getLocaleDayPeriods()`
* `getLocaleDayNames()`
* `getLocaleMonthNames()`
* `getLocaleEraNames()`

Fixes #27003

BREAKING CHANGE:
The locale data API has been marked as returning readonly arrays, rather
than mutable arrays, since these arrays are shared across calls to the
API. If you were mutating them (e.g. calling `sort()`, `push()`, `splice()`, etc)
then your code will not longer compile. If you need to mutate the array, you
should now take a copy (e.g. by calling `slice()`) and mutate the copy.
@artem-galas
Copy link
Contributor Author

@artem-galas artem-galas commented Sep 9, 2020

Branch is rebased to latest master.

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Sep 10, 2020

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Sep 10, 2020

FYI, presubmits (including a global one) went well, this PR is ready for merge.

@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Oct 12, 2020

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 Oct 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

9 participants