From b66f02eb6e49a647188586b7412dbf7a1a25dd53 Mon Sep 17 00:00:00 2001 From: Denis Sikuler Date: Sat, 15 Dec 2018 19:17:18 +0300 Subject: [PATCH] :bug: bug(index): evaluate availabilities lazily (fix #477) (#483) by @gamtiq --- src/index.js | 23 ++++++++++++++++------- src/util.js | 6 ------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/index.js b/src/index.js index 356f338bb..9b80435a1 100644 --- a/src/index.js +++ b/src/index.js @@ -9,9 +9,7 @@ import { isObject, looseClone, remove, - merge, - canUseDateTimeFormat, - canUseNumberFormat + merge } from './util' import BaseFormatter from './format' import I18nPath from './path' @@ -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__' diff --git a/src/util.js b/src/util.js index 546f68837..5891e6b48 100644 --- a/src/util.js +++ b/src/util.js @@ -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'