Skip to content

Commit

Permalink
fix(vue-app): avoid multiple $fetch calls (#7129)
Browse files Browse the repository at this point in the history
Co-authored-by: Aster <duda84@gmail.com>
  • Loading branch information
pi0 and asterd authored Mar 25, 2020
1 parent b82f8d1 commit 0f27f80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/vue-app/template/mixins/fetch.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ function created() {
}
}

async function $fetch() {
function $fetch() {
if (!this._fetchPromise) {
this._fetchPromise = $_fetch.call(this)
.then(() => { delete this._fetchPromise })
}
return this._fetchPromise
}

async function $_fetch() {
this.<%= globals.nuxt %>.nbFetching++
this.$fetchState.pending = true
this.$fetchState.error = null
Expand Down
4 changes: 3 additions & 1 deletion packages/vue-app/template/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,5 +638,7 @@ export function addLifecycleHook(vm, hook, fn) {
if (!vm.$options[hook]) {
vm.$options[hook] = []
}
vm.$options[hook].push(fn)
if (!vm.$options[hook].includes(fn)) {
vm.$options[hook].push(fn)
}
}

0 comments on commit 0f27f80

Please sign in to comment.