Skip to content

Commit

Permalink
Fix issue where getOne and setOne cache reference to the initially-se…
Browse files Browse the repository at this point in the history
…t store. Closes #70
  • Loading branch information
davestewart committed Sep 7, 2019
1 parent c19c26f commit b0a72e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vuex-pathify",
"version": "1.2.4",
"version": "1.2.5",
"description": "Ridiculously simple Vuex setup + wiring",
"main": "dist/vuex-pathify.js",
"module": "dist/vuex-pathify.esm.js",
Expand Down
14 changes: 8 additions & 6 deletions src/helpers/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ export function syncOne (path) {
* @returns {Object} A single getter function
*/
export function getOne (path, stateOnly) {
let getter
let getter, store
return function (...args) {
if (!this.$store) {
throw new Error('[Vuex Pathify] Unexpected condition: this.$store is undefined.\n\nThis is a known edge case with some setups and will cause future lookups to fail')
}
if (!getter) {
getter = makeGetter(this.$store, path, stateOnly)
if (!getter || store !== this.$store) {
store = this.$store
getter = makeGetter(store, path, stateOnly)
}
return getter(...args)
}
Expand All @@ -131,10 +132,11 @@ export function getOne (path, stateOnly) {
* @returns {Function} a single setter function
*/
export function setOne (path) {
let setter
let setter, store
return function (value) {
if (!setter) {
setter = makeSetter(this.$store, path)
if (!setter || store !== this.$store) {
store = this.$store
setter = makeSetter(store, path)
}
this.$nextTick(() => this.$emit('sync', path, value))
return setter(value)
Expand Down

0 comments on commit b0a72e2

Please sign in to comment.