-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support vuex module arrays on components (#98)
* Add support for multiple Vuex Modules per route component * Bump v6.0.0 * Fix order of removals
- Loading branch information
1 parent
bab8c34
commit 5bd47a6
Showing
5 changed files
with
80 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Allow a function to be passed that can generate a route-aware module name | ||
export function getModuleName(vuexModuleDef, route) { | ||
const name = typeof vuexModuleDef.moduleName === 'function' ? | ||
vuexModuleDef.moduleName({ $route: route }) : | ||
vuexModuleDef.moduleName; | ||
return name; | ||
} | ||
|
||
// Return the namespaced module state | ||
function getModuleState(store, nameArr) { | ||
return nameArr.reduce((acc, k) => (acc ? acc[k] : null), store.state); | ||
} | ||
|
||
export function safelyRegisterModule(store, name, vuexModule, logger) { | ||
const nameArr = name.split('/'); | ||
if (store.hasModule(nameArr)) { | ||
logger.info(`Skipping duplicate dynamic Vuex module registration: ${name}`); | ||
} else { | ||
logger.info(`Registering dynamic Vuex module: ${name}`); | ||
store.registerModule(nameArr, vuexModule, { | ||
preserveState: getModuleState(store, nameArr) != null, | ||
}); | ||
} | ||
} |