Skip to content

Commit

Permalink
fix: avoid redefinition of the __ctx__ property (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
1000ch committed Jul 21, 2020
1 parent 895ad65 commit 2598540
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,11 @@ function initGetters<
injectStore: (store) => {
const context = module.context(store)

Object.defineProperty(getters, '__ctx__', {
get: () => context,
})
if (!getters.hasOwnProperty('__ctx__')) {
Object.defineProperty(getters, '__ctx__', {
get: () => context,
})
}

getters.$init(store)
},
Expand Down Expand Up @@ -355,9 +357,12 @@ function initMutations<
mutations: options,
injectStore: (store) => {
const context = module.context(store)
Object.defineProperty(mutations, '__ctx__', {
get: () => context,
})

if (!mutations.hasOwnProperty('__ctx__')) {
Object.defineProperty(mutations, '__ctx__', {
get: () => context,
})
}
},
}
}
Expand Down Expand Up @@ -410,9 +415,11 @@ function initActions<
injectStore: (store) => {
const context = module.context(store)

Object.defineProperty(actions, '__ctx__', {
get: () => context,
})
if (!actions.hasOwnProperty('__ctx__')) {
Object.defineProperty(actions, '__ctx__', {
get: () => context,
})
}

actions.$init(store)
},
Expand Down

0 comments on commit 2598540

Please sign in to comment.