-
Notifications
You must be signed in to change notification settings - Fork 2k
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
i18n: Abstract number-formatters in i18n-calypso. Add caching and numberFormatCompact
abstraction.
#99538
Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~143 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
86b15b4
to
a2455a2
Compare
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
d01f8f7
to
fcc9a31
Compare
numberFormatCompact
abstraction.numberFormatCompact
abstraction.
Also brought the caching from #99110 here. So this should have all the current explorations, main functions in a separate folder, bindings as before, and ready for a package extraction. It will close both https://github.com/Automattic/i18n-issues/issues/941 and https://github.com/Automattic/i18n-issues/issues/926 |
…pact abstraction.
4732f3a
to
80170a1
Compare
I will go ahead and deploy this. Happy to address any feedback in a follow-up. |
Closes https://github.com/Automattic/i18n-issues/issues/941
Closes https://github.com/Automattic/i18n-issues/issues/926
Related to #99110
Proposed Changes
A couple of refactors and additions to i18n-calypso's
numberFormat
Abstractions
numberFormatCompact
abstraction that makes it easier to quickly format "compact" numbers - quite common in stats/etc. Addresses https://github.com/Automattic/i18n-issues/issues/941number-formatters
), which can be extracted later to a package. For the moment, these are exported (internally) as:__DO_NOT_IMPORT__numberFormat
and__DO_NOT_IMPORT__numberFormatCompact
to prevent anyone from importing and using these directly while we complete other refactors.I've written the core handlers' signatures to accept a single object parameter:
The prototype methods haven't changed, so i18n-calypso consumers will still do
numberFormat( 123 )
ornumberFormatCompact( 123 )
for the most part. I find it easier to work on a single-parameter signature, especially if we'll be introducing additional optional parameters next. However, I see the value in doingnumberFormat( number )
for the default cases VSnumberFormat( { number } )
. Aso, not sure what would constitute "options" (all non-required parameters are basically options, so not sure if that's a standard we should follow everywhere or not).Performance Optimization
We introduce caching of the Intl.NumberFormat instance via a
getFormatter
separate function. The approach was tested and benchmarked in a separate PR and incorporated: #99110Why are these changes being made?
Address https://github.com/Automattic/i18n-issues/issues/941
Address https://github.com/Automattic/i18n-issues/issues/926
TODO
Testing Instructions
We will handle migration of "compact" notation in a follow-up. Let's confirm a few
numberFormat
calls for this change:/stats/insights/:site
and confirm numbers render correctly (use FG/a8ckudos sites)/stats/day/:site
and confirm numbers render correctly - also in popovers (use FG/a8ckudos sites)Pre-merge Checklist