Skip to content
This repository was archived by the owner on May 4, 2020. It is now read-only.

Commit 31d1422

Browse files
authored
fix(intl-messageformat): IntlMessageFormat.defaultLocale is upda… (#653)
be a getter in order to enable lazily calculating the actual value when it's needed first time. Also, a new private static member called 'memoizedDefaultLocale' is added to IntlMessageFormat to prevent re-calculating the same defaultLocale each time it's referenced. - resolve: #587
1 parent f1b52da commit 31d1422

File tree

1 file changed

+9
-1
lines changed
  • packages/intl-messageformat/src

1 file changed

+9
-1
lines changed

packages/intl-messageformat/src/core.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,15 @@ export class IntlMessageFormat {
163163
locale: Intl.NumberFormat.supportedLocalesOf(this.locales)[0],
164164
});
165165
getAst = () => this.ast;
166-
static defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
166+
private static memoizedDefaultLocale: string | null = null;
167+
168+
static get defaultLocale() {
169+
if (!IntlMessageFormat.memoizedDefaultLocale) {
170+
IntlMessageFormat.memoizedDefaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
171+
}
172+
173+
return IntlMessageFormat.memoizedDefaultLocale;
174+
}
167175
static __parse: typeof parse | undefined = parse;
168176
// Default format options used as the prototype of the `formats` provided to the
169177
// constructor. These are used when constructing the internal Intl.NumberFormat

0 commit comments

Comments
 (0)