Skip to content

Commit

Permalink
🐛 bug: fix memory leaks
Browse files Browse the repository at this point in the history
Closes #162
  • Loading branch information
kazupon committed May 15, 2017
1 parent d328c61 commit 95be4ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
23 changes: 2 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,18 @@ export default class VueI18n {
}

watchI18nData (fn: Function): Function {
this._i18nWatcher = this._vm.$watch('$data', () => {
return this._vm.$watch('$data', () => {
fn && fn()
}, { deep: true })
return this._i18nWatcher
}

unwatchI18nData (): boolean {
if (this._i18nWatcher) {
this._i18nWatcher()
delete this._i18nWatcher
}
return true
}

watchLocale (fn: Function): ?Function {
if (!this._sync || !this._root) { return null }
const target: any = this._vm
this._watcher = this._root.vm.$watch('locale', (val) => {
return this._root.vm.$watch('locale', (val) => {
target.$set(target, 'locale', val)
fn && fn()
}, { immediate: true })
return this._watcher
}

unwatchLocale (): boolean {
if (!this._sync || !this._watcher) { return false }
if (this._watcher) {
this._watcher()
delete this._watcher
}
return true
}

get vm (): any { return this._vm }
Expand Down
4 changes: 2 additions & 2 deletions src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export default {
if (!this._i18n) { return }

if (this._i18nWatcher) {
this._i18n.unwatchI18nData()
this._i18nWatcher()
delete this._i18nWatcher
}

if (this._localeWatcher) {
this._i18n.unwatchLocale()
this._localeWatcher()
delete this._localeWatcher
}

Expand Down

3 comments on commit 95be4ea

@xingchch
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix cause big issue when vue switch router .

@xingchch
Copy link

@xingchch xingchch commented on 95be4ea Jun 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"vue": "2.3.4",
"vue-router": "2.6.0",
"element-ui": "1.3.7",
A tree component of element-ui with more then 500 items, when swith out from it with vue-router . vue-i18n 6.1.1 is ok . but with version >= 6.1.3, it block the switch more then 7s.

@kazupon
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xingchch
Could you provide the minimum reproduction repo via GitHub issues please?

Please sign in to comment.