Skip to content

Commit 38a0263

Browse files
committed
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]>
1 parent 0edd83e commit 38a0263

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/mixins/store.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*/
2222

23-
import store from '../store/index.js'
23+
import store, { textModule } from '../store/index.js'
2424

2525
/**
2626
* This mixin is required since we cannot be sure that the root Vue instance has
@@ -35,7 +35,11 @@ export default {
3535
},
3636
beforeMount() {
3737
if (typeof this.$store === 'undefined') {
38+
// Store is undefined, e.g. when used through `viewer.js`
3839
this.$store = store
40+
} else if (!this.$store.hasModule('text')) {
41+
// Store lacks text modul (another store exists), e.g. when used as component via NPM package
42+
this.$store.registerModule('text', textModule)
3943
}
4044
},
4145
}

src/store/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const persistentStorage = getBuilder('text').persist().build()
3636

3737
Vue.use(Vuex)
3838

39-
const textModule = {
39+
export const textModule = {
4040
state: {
4141
showAuthorAnnotations: persistentStorage.getItem('showAuthorAnnotations') === 'true',
4242
currentSession: persistentStorage.getItem('currentSession'),

0 commit comments

Comments
 (0)