Skip to content

Commit

Permalink
🐛 bug(index): evaluate availabilities lazily (fix kazupon#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
gamtiq committed Dec 14, 2018
1 parent b4a8c27 commit ec65665
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
23 changes: 16 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import {
isObject,
looseClone,
remove,
merge,
canUseDateTimeFormat,
canUseNumberFormat
merge
} from './util'
import BaseFormatter from './format'
import I18nPath from './path'
Expand Down Expand Up @@ -688,9 +686,20 @@ export default class VueI18n {
}
}

VueI18n.availabilities = {
dateTimeFormat: canUseDateTimeFormat,
numberFormat: canUseNumberFormat
}
let availabilities: IntlAvailability
// $FlowFixMe
Object.defineProperty(VueI18n, 'availabilities', {
get () {
if (!availabilities) {
const intlDefined = typeof Intl !== 'undefined'
availabilities = {
dateTimeFormat: intlDefined && typeof Intl.DateTimeFormat !== 'undefined',
numberFormat: intlDefined && typeof Intl.NumberFormat !== 'undefined'
}
}

return availabilities
}
})
VueI18n.install = install
VueI18n.version = '__VERSION__'
6 changes: 0 additions & 6 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,3 @@ export function looseEqual (a: any, b: any): boolean {
return false
}
}

export const canUseDateTimeFormat: boolean =
typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat !== 'undefined'

export const canUseNumberFormat: boolean =
typeof Intl !== 'undefined' && typeof Intl.NumberFormat !== 'undefined'

0 comments on commit ec65665

Please sign in to comment.