Skip to content

Commit 5056044

Browse files
author
Nedyalko Nikolov
authored
Merge pull request #6 from NativeScript/nnikolov/CachePatternPrepare
Cache for prepared pattern.
2 parents e492143 + cc611b9 commit 5056044

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Diff for: compile.sh

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mkdir -p "$PACK_DIR"
2121
# compile ts
2222
node_modules/.bin/tsc -p "$SOURCE_DIR" --outDir "$PACK_DIR"
2323

24+
# run tslint
2425
node_modules/tslint/bin/tslint --project "$SOURCE_DIR"/tsconfig.json --config "$SOURCE_DIR"/tslint.json
2526

2627
# make commonjs bundle for ANDROID

Diff for: src/nativescript-intl-common.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const LONG = "long";
1010
export const SHORT = "short";
1111
export const TWODIGIT = "2-digit";
1212
export const FULL = "full";
13+
export let resolvedPatterns = new Map();
1314

1415
export class DateTimeFormat implements intlDateTimeFormat {
1516
constructor(private locale?: string, private options?: intlDateTimeFormatOptions, private pattern?: string) {
@@ -200,7 +201,12 @@ export class DateTimeFormat implements intlDateTimeFormat {
200201
if (this.pattern) {
201202
this._preparedPattern = this.pattern;
202203
} else {
203-
this._preparedPattern = this.preparePattern(this.getCorrectPatternForLocale(), this.options);
204+
if (resolvedPatterns.has({locale: this.locale, options: this.options})) {
205+
this._preparedPattern = resolvedPatterns.get({locale: this.locale, options: this.options});
206+
} else {
207+
this._preparedPattern = this.preparePattern(this.getCorrectPatternForLocale(), this.options);
208+
resolvedPatterns.set({locale: this.locale, options: this.options}, this._preparedPattern);
209+
}
204210
}
205211
}
206212
return this._preparedPattern;

0 commit comments

Comments
 (0)