Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Either set vuex store or register text module in store mixin
When a component from the NPM package is used by a vue app with an own
vuex store, we have to expand this store with our text module.

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Nov 16, 2022
commit a71201794b40e7db634514c5f46385d777b65005
6 changes: 5 additions & 1 deletion src/mixins/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/

import store from '../store/index.js'
import store, { textModule } from '../store/index.js'

/**
* This mixin is required since we cannot be sure that the root Vue instance has
Expand All @@ -35,7 +35,11 @@ export default {
},
beforeMount() {
if (typeof this.$store === 'undefined') {
// Store is undefined, e.g. when used through `viewer.js`
this.$store = store
} else if (!this.$store.hasModule('text')) {
// Store lacks text modul (another store exists), e.g. when used as component via NPM package
this.$store.registerModule('text', textModule)
}
},
}
2 changes: 1 addition & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const persistentStorage = getBuilder('text').persist().build()

Vue.use(Vuex)

const textModule = {
export const textModule = {
state: {
showAuthorAnnotations: persistentStorage.getItem('showAuthorAnnotations') === 'true',
currentSession: persistentStorage.getItem('currentSession'),
Expand Down