Skip to content

Commit

Permalink
🐛 bug(mixin): fix cannot create VueI18n instance error for minify pro…
Browse files Browse the repository at this point in the history
…duction
  • Loading branch information
kazupon committed Mar 11, 2017
1 parent 8f04abc commit 7eeb29f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/mixin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */

import VueI18n from './index'
import { typeName, isPlainObject, warn } from './util'
import { isPlainObject, warn } from './util'

export default {
computed: {
Expand Down Expand Up @@ -45,11 +45,11 @@ export default {
beforeCreate () {
const options: any = this.$options
if (options.i18n) {
if (typeName(options.i18n) === 'VueI18n') {
if (options.i18n instanceof VueI18n) {
this.$i18n = options.i18n
} else if (isPlainObject(options.i18n)) {
// component local i18n
if (this.$root && this.$root.$i18n && typeName(this.$root.$i18n) === 'VueI18n') {
if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
options.i18n.root = this.$root.$i18n
}
this.$i18n = new VueI18n(options.i18n)
Expand All @@ -61,7 +61,7 @@ export default {
warn(`Cannot be interpreted 'i18n' option.`)
}
}
} else if (this.$root && this.$root.$i18n && typeName(this.$root.$i18n) === 'VueI18n') {
} else if (this.$root && this.$root.$i18n && this.$root.$i18n instanceof VueI18n) {
// root i18n
this.$i18n = this.$root.$i18n
}
Expand Down
21 changes: 0 additions & 21 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,6 @@ export function isPlainObject (obj: any): boolean {
return toString.call(obj) === OBJECT_STRING
}

function funcName (f: Function): string {
if (f.name) { return f.name }
const match = /^\s*function\s*([^\(]*)/im.exec(f.toString())
return match ? match[1] : ''
}

function ctorName (obj: any): string {
const str = toString.call(obj).slice(8, -1)
if ((str === 'Object' || str === 'Error') && obj.constructor) {
return funcName(obj.constructor)
}
return str
}

export function typeName (val: mixed): string {
if (val === null) { return 'null' }
const type: string = typeof val
if (type === 'object') { return ctorName(val) }
return type
}

export function isNull (val: mixed): boolean {
return val === null || val === undefined
}
Expand Down

0 comments on commit 7eeb29f

Please sign in to comment.