Skip to content

Commit

Permalink
perf(common): make NgLocalization token tree-shakable
Browse files Browse the repository at this point in the history
This commit updates the `NgLocalization` token to become tree-shakable (vs using a direct reference to that token in the `providers` section of the `CommonModule`). The `NgLocalization` token is used for apps that use i18n and for other apps it would be excluded from the bundle.
  • Loading branch information
AndrewKushnir committed Feb 17, 2022
1 parent db4a658 commit 9a6e233
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 110 deletions.
4 changes: 4 additions & 0 deletions goldens/public-api/common/common.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ export class NgLocaleLocalization extends NgLocalization {
export abstract class NgLocalization {
// (undocumented)
abstract getPluralCategory(value: any, locale?: string): string;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<NgLocalization, never>;
// (undocumented)
static ɵprov: i0.ɵɵInjectableDeclaration<NgLocalization>;
}

// @public
Expand Down
2 changes: 1 addition & 1 deletion goldens/size-tracking/aio-payloads.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"master": {
"uncompressed": {
"runtime": 4343,
"main": 450729,
"main": 449841,
"polyfills": 37297,
"styles": 70379,
"light-theme": 77582,
Expand Down
12 changes: 6 additions & 6 deletions goldens/size-tracking/integration-payloads.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"master": {
"uncompressed": {
"runtime": 1083,
"main": 127944,
"main": 126007,
"polyfills": 37226
}
}
Expand All @@ -24,7 +24,7 @@
"master": {
"uncompressed": {
"runtime": 1105,
"main": 133608,
"main": 132995,
"polyfills": 37248
}
}
Expand All @@ -33,7 +33,7 @@
"master": {
"uncompressed": {
"runtime": 929,
"main": 126275,
"main": 125690,
"polyfills": 37933
}
}
Expand All @@ -42,7 +42,7 @@
"master": {
"uncompressed": {
"runtime": 2835,
"main": 233348,
"main": 232795,
"polyfills": 37244,
"src_app_lazy_lazy_module_ts": 795
}
Expand All @@ -52,7 +52,7 @@
"master": {
"uncompressed": {
"runtime": 1063,
"main": 159637,
"main": 156872,
"polyfills": 36975
}
}
Expand All @@ -61,7 +61,7 @@
"master": {
"uncompressed": {
"runtime": 1070,
"main": 159755,
"main": 157264,
"polyfills": 37242
}
}
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/common_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
*/

import {NgModule} from '@angular/core';

import {COMMON_DIRECTIVES} from './directives/index';
import {NgLocaleLocalization, NgLocalization} from './i18n/localization';
import {COMMON_PIPES} from './pipes/index';



// Note: This does not contain the location providers,
// as they need some platform specific implementations to work.
/**
Expand All @@ -30,9 +31,6 @@ import {COMMON_PIPES} from './pipes/index';
@NgModule({
declarations: [COMMON_DIRECTIVES, COMMON_PIPES],
exports: [COMMON_DIRECTIVES, COMMON_PIPES],
providers: [
{provide: NgLocalization, useClass: NgLocaleLocalization},
],
})
export class CommonModule {
}
9 changes: 6 additions & 3 deletions packages/common/src/i18n/localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Inject, Injectable, LOCALE_ID} from '@angular/core';
import {forwardRef, Inject, inject, Injectable, LOCALE_ID} from '@angular/core';

import {getLocalePluralCase, Plural} from './locale_data_api';


/**
* @publicApi
*/
@Injectable({
providedIn: 'root',
useClass: forwardRef(() => NgLocaleLocalization),
deps: [LOCALE_ID],
})
export abstract class NgLocalization {
abstract getPluralCategory(value: any, locale?: string): string;
}


/**
* Returns the plural category for a given value.
* - "=value" when the case exists,
Expand Down
24 changes: 0 additions & 24 deletions packages/core/test/bundling/animations/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,12 @@
{
"name": "LEAVE_TOKEN_REGEX"
},
{
"name": "LOCALE_DATA"
},
{
"name": "LOCALE_ID2"
},
{
"name": "LifecycleHooksFeature"
},
{
"name": "LocaleDataIndex"
},
{
"name": "MODIFIER_KEYS"
},
Expand Down Expand Up @@ -338,12 +332,6 @@
{
"name": "NULL_REMOVED_QUERIED_STATE"
},
{
"name": "NgLocaleLocalization"
},
{
"name": "NgLocalization"
},
{
"name": "NgModuleFactory2"
},
Expand Down Expand Up @@ -392,9 +380,6 @@
{
"name": "PlatformRef"
},
{
"name": "Plural"
},
{
"name": "R3Injector"
},
Expand Down Expand Up @@ -875,9 +860,6 @@
{
"name": "getLViewParent"
},
{
"name": "getLocaleData"
},
{
"name": "getNativeByTNode"
},
Expand Down Expand Up @@ -1103,9 +1085,6 @@
{
"name": "listenOnPlayer"
},
{
"name": "locale_en_default"
},
{
"name": "lookupTokenUsingModuleInjector"
},
Expand Down Expand Up @@ -1373,9 +1352,6 @@
{
"name": "transition"
},
{
"name": "u"
},
{
"name": "unwrapRNode"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,12 @@
{
"name": "KeyEventsPlugin"
},
{
"name": "LOCALE_DATA"
},
{
"name": "LOCALE_ID2"
},
{
"name": "LifecycleHooksFeature"
},
{
"name": "LocaleDataIndex"
},
{
"name": "MODIFIER_KEYS"
},
Expand Down Expand Up @@ -341,12 +335,6 @@
{
"name": "NgForOf"
},
{
"name": "NgLocaleLocalization"
},
{
"name": "NgLocalization"
},
{
"name": "NgModuleFactory2"
},
Expand Down Expand Up @@ -389,9 +377,6 @@
{
"name": "PlatformRef"
},
{
"name": "Plural"
},
{
"name": "R3Injector"
},
Expand Down Expand Up @@ -920,9 +905,6 @@
{
"name": "getLViewParent"
},
{
"name": "getLocaleData"
},
{
"name": "getNativeByTNode"
},
Expand Down Expand Up @@ -1220,9 +1202,6 @@
{
"name": "leaveViewLight"
},
{
"name": "locale_en_default"
},
{
"name": "lookupTokenUsingModuleInjector"
},
Expand Down Expand Up @@ -1532,9 +1511,6 @@
{
"name": "trackByIdentity"
},
{
"name": "u"
},
{
"name": "unwrapRNode"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,12 @@
{
"name": "KeyEventsPlugin"
},
{
"name": "LOCALE_DATA"
},
{
"name": "LOCALE_ID2"
},
{
"name": "LifecycleHooksFeature"
},
{
"name": "LocaleDataIndex"
},
{
"name": "MODIFIER_KEYS"
},
Expand Down Expand Up @@ -332,12 +326,6 @@
{
"name": "NgForm"
},
{
"name": "NgLocaleLocalization"
},
{
"name": "NgLocalization"
},
{
"name": "NgModel"
},
Expand Down Expand Up @@ -386,9 +374,6 @@
{
"name": "PlatformRef"
},
{
"name": "Plural"
},
{
"name": "R3Injector"
},
Expand Down Expand Up @@ -893,9 +878,6 @@
{
"name": "getLViewParent"
},
{
"name": "getLocaleData"
},
{
"name": "getNativeByTNode"
},
Expand Down Expand Up @@ -1187,9 +1169,6 @@
{
"name": "leaveViewLight"
},
{
"name": "locale_en_default"
},
{
"name": "lookupTokenUsingModuleInjector"
},
Expand Down Expand Up @@ -1517,9 +1496,6 @@
{
"name": "trackByIdentity"
},
{
"name": "u"
},
{
"name": "unwrapRNode"
},
Expand Down

0 comments on commit 9a6e233

Please sign in to comment.