Skip to content

Commit

Permalink
fix(vuex): early unregister module, closes vuejs#922
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau authored and iksim committed Apr 18, 2019
1 parent 6801c8c commit 51ba8ad
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/backend/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ export function installHook (target) {
if (typeof path === 'string') path = [path]
hook.storeModules.push({ path, module, options })
origRegister(path, module, options)
if (process.env.NODE_ENV !== 'production') console.log('early register module', path)
}
const origUnregister = store.unregisterModule.bind(store)
store.unregisterModule = (path) => {
if (typeof path === 'string') path = [path]
const key = path.join('/')
const index = hook.storeModules.findIndex(m => m.path.join('/') === key)
if (index !== -1) hook.storeModules.splice(0, 1)
if (index !== -1) hook.storeModules.splice(index, 1)
origUnregister(path)
if (process.env.NODE_ENV !== 'production') console.log('early unregister module', path)
}
hook.flushStoreModules = () => {
store.registerModule = origRegister
Expand Down

0 comments on commit 51ba8ad

Please sign in to comment.