Skip to content

Commit

Permalink
⚡ improvement(index): fix mergeLocaleMessage. add changes notificatio…
Browse files Browse the repository at this point in the history
…n on merging with an empty target object (#752) by @jekill
  • Loading branch information
jekill authored and kazupon committed Dec 18, 2019
1 parent c226fc3 commit 048eac5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ export default class VueI18n {
this._checkLocaleMessage(locale, this._warnHtmlInMessage, message)
if (this._warnHtmlInMessage === 'error') { return }
}
this._vm.$set(this._vm.messages, locale, merge(this._vm.messages[locale] || {}, message))
this._vm.$set(this._vm.messages, locale, merge({}, this._vm.messages[locale] || {}, message))
}
getDateTimeFormat (locale: Locale): DateTimeFormat {
Expand Down
16 changes: 16 additions & 0 deletions test/unit/message.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,20 @@ describe('message', () => {
assert.deepEqual({ foo: 'bar', bar: 'foo' }, i18n.getLocaleMessage('en'))
})
})

it('Should be merged and notified if the target is empty', (done) => {
const i18n = new VueI18n({
locale: 'ru',
messages: {
ru: {}
}
})
const uw = i18n._vm.$watch('messages.ru.foo', (newVal, oldVal, o) => {
assert.equal(newVal, 'бар');
uw();
done();
});
i18n.mergeLocaleMessage('ru', { foo: 'бар' })
assert.deepEqual({ foo: 'бар' }, i18n.getLocaleMessage('ru'))
})
})

0 comments on commit 048eac5

Please sign in to comment.