Skip to content

Commit

Permalink
💥 breaking: drop vue 1.0 supporting
Browse files Browse the repository at this point in the history
Closes #105
  • Loading branch information
kazupon committed Feb 4, 2017
1 parent 0223942 commit 4da26cf
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 136 deletions.
8 changes: 3 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ function plugin (Vue, opts = {}) {
return
}

if (process.env.NODE_ENV !== 'production' && version < 1) {
warn('vue-i18n (' + plugin.version
+ ') need to use vue version 1.0 or later (vue version: '
+ Vue.version + ').')
if (process.env.NODE_ENV !== 'production' && version < 2) {
warn(`vue-i18n (${plugin.version}) need to use Vue 2.0 or later (Vue: ${Vue.version}).`)
return
}

const lang = 'en'
setupLangVM(Vue, lang)

Asset(Vue, langVM)
Override(Vue, langVM, version)
Override(Vue, langVM)
Config(Vue, langVM, lang)
Extend(Vue)
}
Expand Down
15 changes: 2 additions & 13 deletions src/override.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
export default function (Vue, langVM, version) {
function update (vm) {
if (version > 1) {
vm.$forceUpdate()
} else {
let i = vm._watchers.length
while (i--) {
vm._watchers[i].update(true) // shallow updates
}
}
}

export default function (Vue, langVM) {
// override _init
const init = Vue.prototype._init
Vue.prototype._init = function (options) {
Expand All @@ -18,7 +7,7 @@ export default function (Vue, langVM, version) {
if (!this.$parent) { // root
this._$lang = langVM
this._langUnwatch = this._$lang.$watch('$data', (val, old) => {
update(this)
this.$forceUpdate()
}, { deep: true })
}
}
Expand Down
18 changes: 4 additions & 14 deletions test/specs/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import locales from './fixture/locales'


describe('component locales', () => {
const version = Number(Vue.version.split('.')[0])

before(done => {
Object.keys(locales).forEach(lang => {
Vue.locale(lang, locales[lang])
Expand All @@ -31,25 +29,17 @@ describe('component locales', () => {
}
}
}
if (version >= 2) {
compOptions.render = function (h) {
return h('p', {}, [this.$t('foo.bar.buz')])
}
} else {
compOptions.template = '<p>{{* $t("foo.bar.buz") }}</p>'
compOptions.render = function (h) {
return h('p', {}, [this.$t('foo.bar.buz')])
}

const options = {
el,
components: { component1: compOptions }
}

if (version >= 2) {
options.render = function (h) {
return h('div', {}, [h('component1', {})])
}
} else {
options.template = '<div><component1></component1></div>'
options.render = function (h) {
return h('div', {}, [h('component1', {})])
}

vm = new Vue(options)
Expand Down
12 changes: 2 additions & 10 deletions test/specs/hot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import Vue from 'vue'
import locales from './fixture/locales'

describe('hot reloading', () => {
const version = Number(Vue.version.split('.')[0])

let el
let orgLocale
const expectLocale = 'the world updated'
Expand Down Expand Up @@ -34,17 +32,11 @@ describe('hot reloading', () => {
el,
data () { return { lang: 'en' } }
}

if (version >= 2) {
options.render = function (h) {
return h('p', {}, [this.$t('message.hello', this.lang)])
}
} else {
options.template = '<p>{{ $t("message.hello", lang) }}</p>'
options.render = function (h) {
return h('p', {}, [this.$t('message.hello', this.lang)])
}

const vm = new Vue(options)

Vue.nextTick(() => {
assert.equal(vm.$el.textContent, locales.en.message.hello)

Expand Down
138 changes: 44 additions & 94 deletions test/specs/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import locales from './fixture/locales'


describe('i18n', () => {
const version = Number(Vue.version.split('.')[0])

before(done => {
Object.keys(locales).forEach(lang => {
Vue.locale(lang, locales[lang])
Expand Down Expand Up @@ -540,13 +538,8 @@ describe('i18n', () => {
return { lang: 'en' }
}
}

if (version >= 2) {
options.render = function (h) {
return h('p', {}, [this.$t('message.hello', this.lang)])
}
} else {
options.template = '<p>{{ $t("message.hello", lang) }}</p>'
options.render = function (h) {
return h('p', {}, [this.$t('message.hello', this.lang)])
}

const vm = new Vue(options)
Expand All @@ -572,28 +565,20 @@ describe('i18n', () => {

it('should translate', done => {
const compOptions = {}
if (version >= 2) {
compOptions.render = function (h) {
return h('p', {}, [this.$t('message.hoge')])
}
} else {
compOptions.template = '<p>{{* $t("message.hoge") }}</p>'
compOptions.render = function (h) {
return h('p', {}, [this.$t('message.hoge')])
}

const options = {
el,
components: { hoge: compOptions }
}

if (version >= 2) {
options.render = function (h) {
return h('div', {}, [
h('p', {}, [this.$t('message.hello')]),
h('hoge', {})
])
}
} else {
options.template = '<div><p>{{ $t("message.hello") }}</p><hoge></hoge></div>'
options.render = function (h) {
return h('div', {}, [
h('p', {}, [this.$t('message.hello')]),
h('hoge', {})
])
}

const vm = new Vue(options)
Expand Down Expand Up @@ -651,7 +636,6 @@ describe('i18n', () => {
})

it('should translate', done => {
let vm
const parentLocales = {
en: { foo: { bar: 'hello parent' } },
ja: { foo: { bar: 'こんにちは、親' } }
Expand All @@ -669,79 +653,45 @@ describe('i18n', () => {
ja: { foo: { bar: 'こんにちは、子3' } }
}

if (version >= 2) {
vm = new Vue({
render (h) {
return h('div', [
h('p', { attrs: { id: 'parent' } }, [this.$t('foo.bar')]),
h('child1'),
h('child2')
])
},
locales: parentLocales,
components: {
child1: {
render (h) {
return h('div', [
h('p', { attrs: { id: 'child1' } }, [this.$t('foo.bar')]),
h('child3')
])
},
locales: child1Locales,
components: {
child3: {
render (h) {
return h('div', [
h('p', { attrs: { id: 'child3' } }, [this.$t('foo.bar')])
])
},
locales: child3Locales
}
}
const vm = new Vue({
render (h) {
return h('div', [
h('p', { attrs: { id: 'parent' } }, [this.$t('foo.bar')]),
h('child1'),
h('child2')
])
},
locales: parentLocales,
components: {
child1: {
render (h) {
return h('div', [
h('p', { attrs: { id: 'child1' } }, [this.$t('foo.bar')]),
h('child3')
])
},
child2: {
render (h) {
return h('div', [
h('p', { attrs: { id: 'child2' } }, [this.$t('foo.bar')])
])
},
locales: child2Locales
}
}
})
} else {
vm = new Vue({
template: `<div>
<p id="parent">{{ $t("foo.bar") }}</p>
<child1></child1>
<child2></child2>
</div>`,
locales: parentLocales,
components: {
child1: {
template: `<div>
<p id="child1">{{ $t("foo.bar") }}</p>
<child3></child3>
</div>`,
locales: child1Locales,
components: {
child3: {
template: `<div>
<p id="child3">{{ $t("foo.bar") }}</p>
</div>`,
locales: child3Locales
}
locales: child1Locales,
components: {
child3: {
render (h) {
return h('div', [
h('p', { attrs: { id: 'child3' } }, [this.$t('foo.bar')])
])
},
locales: child3Locales
}
},
child2: {
template: `<div>
<p id="child2">{{ $t("foo.bar") }}</p>
</div>`,
locales: child2Locales
}
},
child2: {
render (h) {
return h('div', [
h('p', { attrs: { id: 'child2' } }, [this.$t('foo.bar')])
])
},
locales: child2Locales
}
})
}
}
})
vm.$mount(el)

const parent = vm.$el.querySelector('#parent')
Expand Down

0 comments on commit 4da26cf

Please sign in to comment.