ソースを参照

use reselector in native formatting

Adam Shaw 7 年 前
コミット
2b28dc1ef4
1 ファイル変更5 行追加1 行削除
  1. 5 1
      src/datelib/formatting-native.ts

+ 5 - 1
src/datelib/formatting-native.ts

@@ -3,6 +3,7 @@ import { DateMarker, timeAsMs } from './marker'
 import { CalendarSystem } from './calendar-system'
 import { Locale } from './locale'
 import { DateFormatter, DateFormattingContext, ZonedMarker, formatTimeZoneOffset } from './formatting'
+import reselector from '../util/reselector'
 
 const EXTENDED_SETTINGS_AND_SEVERITIES = {
   week: 3,
@@ -35,6 +36,7 @@ export class NativeFormatter implements DateFormatter {
   standardDateProps: any
   extendedSettings: any
   severity: number
+  private buildFormattingFunc: typeof buildFormattingFunc // caching for efficiency with same date env
 
   constructor(formatSettings) {
     let standardDateProps: any = {}
@@ -57,10 +59,12 @@ export class NativeFormatter implements DateFormatter {
     this.standardDateProps = standardDateProps
     this.extendedSettings = extendedSettings
     this.severity = severity
+
+    this.buildFormattingFunc = reselector(buildFormattingFunc)
   }
 
   format(date: ZonedMarker, context: DateFormattingContext) {
-    return buildFormattingFunc(this.standardDateProps, this.extendedSettings, context)(date) // TODO: use reselector
+    return this.buildFormattingFunc(this.standardDateProps, this.extendedSettings, context)(date)
   }
 
   formatRange(start: ZonedMarker, end: ZonedMarker, context: DateFormattingContext) {