Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hacky vuex-module-decorators fix for preserveState
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators'
type ModulePreserveState = Module
export { Module, ModulePreserveState, VuexModule, Mutation, Action }
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