Created
July 20, 2019 03:10
-
-
Save vhqtvn/df3782d66e40862a664cf1e5c54487ac to your computer and use it in GitHub Desktop.
Hacky vuex-module-decorators fix for preserveState
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators' | |
type ModulePreserveState = Module | |
export { Module, ModulePreserveState, VuexModule, Mutation, Action } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators' | |
let origModule = Module | |
Module = function(modOrOpt){ | |
if (typeof (modOrOpt) === 'function') { | |
origModule({})(modOrOpt); | |
} else { | |
if (modOrOpt && modOrOpt.dynamic) { | |
let orig = modOrOpt.store.registerModule; | |
modOrOpt.store.registerModule = function registerModuleHack(a,b,c){ | |
if(typeof c === 'undefined') { | |
c = { preserveState: false } | |
} | |
return orig.call(this,a,b,c); | |
} | |
} | |
return origModule(modOrOpt) | |
} | |
} | |
ModulePreserveState = function(modOrOpt){ | |
if (typeof (modOrOpt) === 'function') { | |
origModule({})(modOrOpt); | |
} else { | |
if (modOrOpt && modOrOpt.dynamic) { | |
let orig = modOrOpt.store.registerModule; | |
modOrOpt.store.registerModule = function registerModuleHack(a,b,c){ | |
if(typeof c === 'undefined') { | |
c = { preserveState: true } | |
} | |
return orig.call(this,a,b,c); | |
} | |
} | |
return origModule(modOrOpt) | |
} | |
} | |
export {Module, ModulePreserveState, VuexModule, Mutation, Action} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment