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

Commit 048eac5

Browse files
jekillkazupon
authored andcommittedDec 18, 2019
⚡ improvement(index): fix mergeLocaleMessage. add changes notification on merging with an empty target object (#752) by @jekill
1 parent c226fc3 commit 048eac5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
 

‎src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ export default class VueI18n {
612612
this._checkLocaleMessage(locale, this._warnHtmlInMessage, message)
613613
if (this._warnHtmlInMessage === 'error') { return }
614614
}
615-
this._vm.$set(this._vm.messages, locale, merge(this._vm.messages[locale] || {}, message))
615+
this._vm.$set(this._vm.messages, locale, merge({}, this._vm.messages[locale] || {}, message))
616616
}
617617

618618
getDateTimeFormat (locale: Locale): DateTimeFormat {

‎test/unit/message.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,20 @@ describe('message', () => {
7979
assert.deepEqual({ foo: 'bar', bar: 'foo' }, i18n.getLocaleMessage('en'))
8080
})
8181
})
82+
83+
it('Should be merged and notified if the target is empty', (done) => {
84+
const i18n = new VueI18n({
85+
locale: 'ru',
86+
messages: {
87+
ru: {}
88+
}
89+
})
90+
const uw = i18n._vm.$watch('messages.ru.foo', (newVal, oldVal, o) => {
91+
assert.equal(newVal, 'бар');
92+
uw();
93+
done();
94+
});
95+
i18n.mergeLocaleMessage('ru', { foo: 'бар' })
96+
assert.deepEqual({ foo: 'бар' }, i18n.getLocaleMessage('ru'))
97+
})
8298
})

0 commit comments

Comments
 (0)
This repository has been archived.