Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit 4da26cf

Browse files
committed
💥 breaking: drop vue 1.0 supporting
Closes #105
1 parent 0223942 commit 4da26cf

File tree

5 files changed

+55
-136
lines changed

5 files changed

+55
-136
lines changed

src/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ function plugin (Vue, opts = {}) {
2222
return
2323
}
2424

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

3230
const lang = 'en'
3331
setupLangVM(Vue, lang)
3432

3533
Asset(Vue, langVM)
36-
Override(Vue, langVM, version)
34+
Override(Vue, langVM)
3735
Config(Vue, langVM, lang)
3836
Extend(Vue)
3937
}

src/override.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
export default function (Vue, langVM, version) {
2-
function update (vm) {
3-
if (version > 1) {
4-
vm.$forceUpdate()
5-
} else {
6-
let i = vm._watchers.length
7-
while (i--) {
8-
vm._watchers[i].update(true) // shallow updates
9-
}
10-
}
11-
}
12-
1+
export default function (Vue, langVM) {
132
// override _init
143
const init = Vue.prototype._init
154
Vue.prototype._init = function (options) {
@@ -18,7 +7,7 @@ export default function (Vue, langVM, version) {
187
if (!this.$parent) { // root
198
this._$lang = langVM
209
this._langUnwatch = this._$lang.$watch('$data', (val, old) => {
21-
update(this)
10+
this.$forceUpdate()
2211
}, { deep: true })
2312
}
2413
}

test/specs/component.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import locales from './fixture/locales'
44

55

66
describe('component locales', () => {
7-
const version = Number(Vue.version.split('.')[0])
8-
97
before(done => {
108
Object.keys(locales).forEach(lang => {
119
Vue.locale(lang, locales[lang])
@@ -31,25 +29,17 @@ describe('component locales', () => {
3129
}
3230
}
3331
}
34-
if (version >= 2) {
35-
compOptions.render = function (h) {
36-
return h('p', {}, [this.$t('foo.bar.buz')])
37-
}
38-
} else {
39-
compOptions.template = '<p>{{* $t("foo.bar.buz") }}</p>'
32+
compOptions.render = function (h) {
33+
return h('p', {}, [this.$t('foo.bar.buz')])
4034
}
4135

4236
const options = {
4337
el,
4438
components: { component1: compOptions }
4539
}
4640

47-
if (version >= 2) {
48-
options.render = function (h) {
49-
return h('div', {}, [h('component1', {})])
50-
}
51-
} else {
52-
options.template = '<div><component1></component1></div>'
41+
options.render = function (h) {
42+
return h('div', {}, [h('component1', {})])
5343
}
5444

5545
vm = new Vue(options)

test/specs/hot.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import Vue from 'vue'
33
import locales from './fixture/locales'
44

55
describe('hot reloading', () => {
6-
const version = Number(Vue.version.split('.')[0])
7-
86
let el
97
let orgLocale
108
const expectLocale = 'the world updated'
@@ -34,17 +32,11 @@ describe('hot reloading', () => {
3432
el,
3533
data () { return { lang: 'en' } }
3634
}
37-
38-
if (version >= 2) {
39-
options.render = function (h) {
40-
return h('p', {}, [this.$t('message.hello', this.lang)])
41-
}
42-
} else {
43-
options.template = '<p>{{ $t("message.hello", lang) }}</p>'
35+
options.render = function (h) {
36+
return h('p', {}, [this.$t('message.hello', this.lang)])
4437
}
4538

4639
const vm = new Vue(options)
47-
4840
Vue.nextTick(() => {
4941
assert.equal(vm.$el.textContent, locales.en.message.hello)
5042

test/specs/i18n.js

Lines changed: 44 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import locales from './fixture/locales'
44

55

66
describe('i18n', () => {
7-
const version = Number(Vue.version.split('.')[0])
8-
97
before(done => {
108
Object.keys(locales).forEach(lang => {
119
Vue.locale(lang, locales[lang])
@@ -540,13 +538,8 @@ describe('i18n', () => {
540538
return { lang: 'en' }
541539
}
542540
}
543-
544-
if (version >= 2) {
545-
options.render = function (h) {
546-
return h('p', {}, [this.$t('message.hello', this.lang)])
547-
}
548-
} else {
549-
options.template = '<p>{{ $t("message.hello", lang) }}</p>'
541+
options.render = function (h) {
542+
return h('p', {}, [this.$t('message.hello', this.lang)])
550543
}
551544

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

573566
it('should translate', done => {
574567
const compOptions = {}
575-
if (version >= 2) {
576-
compOptions.render = function (h) {
577-
return h('p', {}, [this.$t('message.hoge')])
578-
}
579-
} else {
580-
compOptions.template = '<p>{{* $t("message.hoge") }}</p>'
568+
compOptions.render = function (h) {
569+
return h('p', {}, [this.$t('message.hoge')])
581570
}
582571

583572
const options = {
584573
el,
585574
components: { hoge: compOptions }
586575
}
587576

588-
if (version >= 2) {
589-
options.render = function (h) {
590-
return h('div', {}, [
591-
h('p', {}, [this.$t('message.hello')]),
592-
h('hoge', {})
593-
])
594-
}
595-
} else {
596-
options.template = '<div><p>{{ $t("message.hello") }}</p><hoge></hoge></div>'
577+
options.render = function (h) {
578+
return h('div', {}, [
579+
h('p', {}, [this.$t('message.hello')]),
580+
h('hoge', {})
581+
])
597582
}
598583

599584
const vm = new Vue(options)
@@ -651,7 +636,6 @@ describe('i18n', () => {
651636
})
652637

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

672-
if (version >= 2) {
673-
vm = new Vue({
674-
render (h) {
675-
return h('div', [
676-
h('p', { attrs: { id: 'parent' } }, [this.$t('foo.bar')]),
677-
h('child1'),
678-
h('child2')
679-
])
680-
},
681-
locales: parentLocales,
682-
components: {
683-
child1: {
684-
render (h) {
685-
return h('div', [
686-
h('p', { attrs: { id: 'child1' } }, [this.$t('foo.bar')]),
687-
h('child3')
688-
])
689-
},
690-
locales: child1Locales,
691-
components: {
692-
child3: {
693-
render (h) {
694-
return h('div', [
695-
h('p', { attrs: { id: 'child3' } }, [this.$t('foo.bar')])
696-
])
697-
},
698-
locales: child3Locales
699-
}
700-
}
656+
const vm = new Vue({
657+
render (h) {
658+
return h('div', [
659+
h('p', { attrs: { id: 'parent' } }, [this.$t('foo.bar')]),
660+
h('child1'),
661+
h('child2')
662+
])
663+
},
664+
locales: parentLocales,
665+
components: {
666+
child1: {
667+
render (h) {
668+
return h('div', [
669+
h('p', { attrs: { id: 'child1' } }, [this.$t('foo.bar')]),
670+
h('child3')
671+
])
701672
},
702-
child2: {
703-
render (h) {
704-
return h('div', [
705-
h('p', { attrs: { id: 'child2' } }, [this.$t('foo.bar')])
706-
])
707-
},
708-
locales: child2Locales
709-
}
710-
}
711-
})
712-
} else {
713-
vm = new Vue({
714-
template: `<div>
715-
<p id="parent">{{ $t("foo.bar") }}</p>
716-
<child1></child1>
717-
<child2></child2>
718-
</div>`,
719-
locales: parentLocales,
720-
components: {
721-
child1: {
722-
template: `<div>
723-
<p id="child1">{{ $t("foo.bar") }}</p>
724-
<child3></child3>
725-
</div>`,
726-
locales: child1Locales,
727-
components: {
728-
child3: {
729-
template: `<div>
730-
<p id="child3">{{ $t("foo.bar") }}</p>
731-
</div>`,
732-
locales: child3Locales
733-
}
673+
locales: child1Locales,
674+
components: {
675+
child3: {
676+
render (h) {
677+
return h('div', [
678+
h('p', { attrs: { id: 'child3' } }, [this.$t('foo.bar')])
679+
])
680+
},
681+
locales: child3Locales
734682
}
735-
},
736-
child2: {
737-
template: `<div>
738-
<p id="child2">{{ $t("foo.bar") }}</p>
739-
</div>`,
740-
locales: child2Locales
741683
}
684+
},
685+
child2: {
686+
render (h) {
687+
return h('div', [
688+
h('p', { attrs: { id: 'child2' } }, [this.$t('foo.bar')])
689+
])
690+
},
691+
locales: child2Locales
742692
}
743-
})
744-
}
693+
}
694+
})
745695
vm.$mount(el)
746696

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

0 commit comments

Comments
 (0)