mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-22 20:38:55 -05:00
fix(ui): IPC API memory leak
This commit is contained in:
@@ -25,6 +25,7 @@ class PluginApi {
|
||||
this.clientAddons = []
|
||||
this.views = []
|
||||
this.actions = new Map()
|
||||
this.ipcHandlers = []
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,6 +195,7 @@ class PluginApi {
|
||||
* @param {function} cb Callback with 'data' param
|
||||
*/
|
||||
ipcOn (cb) {
|
||||
this.ipcHandlers.push(cb)
|
||||
return ipc.on(cb)
|
||||
}
|
||||
|
||||
@@ -203,6 +205,8 @@ class PluginApi {
|
||||
* @param {any} cb Callback to be removed
|
||||
*/
|
||||
ipcOff (cb) {
|
||||
const index = this.ipcHandlers.indexOf(cb)
|
||||
if (index !== -1) this.ipcHandlers.splice(index, 1)
|
||||
ipc.off(cb)
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ const PluginApi = require('../api/PluginApi')
|
||||
// Utils
|
||||
const { getCommand } = require('../utils/command')
|
||||
const { getBasePath } = require('../utils/serve')
|
||||
const ipc = require('../utils/ipc')
|
||||
|
||||
const PROGRESS_ID = 'plugin-installation'
|
||||
|
||||
@@ -83,6 +84,7 @@ function resetPluginApi (context) {
|
||||
// Clean up
|
||||
if (pluginApi) {
|
||||
pluginApi.views.forEach(r => views.remove(r.id, context))
|
||||
pluginApi.ipcHandlers.forEach(fn => ipc.off(fn))
|
||||
}
|
||||
|
||||
pluginApi = new PluginApi(context)
|
||||
|
||||
Reference in New Issue
Block a user