Skip to content

Commit 534beff

Browse files
author
Guillaume Chau
committed
refactor: callHandlers fix #108
1 parent 05df318 commit 534beff

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/smart-apollo.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,28 @@ export default class SmartApollo {
138138
throw new Error('Not implemented')
139139
}
140140

141-
errorHandler (...args) {
141+
callHandlers (handlers, ...args) {
142142
let catched = false
143-
if (this.options.error) {
144-
this.options.error.call(this.vm, ...args)
145-
catched = true
146-
}
147-
if (this.vm.$apollo.error) {
148-
this.vm.$apollo.error.call(this.vm, ...args)
149-
catched = true
150-
}
151-
if (this.vm.$apollo.provider.errorHandler) {
152-
this.vm.$apollo.provider.errorHandler.call(this.vm, ...args)
153-
catched = true
143+
for (const handler of handlers) {
144+
if (handler) {
145+
catched = true
146+
let result = handler.call(this.vm, ...args)
147+
if (typeof result !== 'undefined' && !result) {
148+
break
149+
}
150+
}
154151
}
155152
return catched
156153
}
157154

155+
errorHandler (...args) {
156+
return this.callHandlers([
157+
this.options.error,
158+
this.vm.$apollo.error,
159+
this.vm.$apollo.provider.errorHandler,
160+
], ...args)
161+
}
162+
158163
catchError (error) {
159164
const catched = this.errorHandler(error)
160165

src/smart-query.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ export default class SmartQuery extends SmartApollo {
151151
}
152152

153153
watchLoading (...args) {
154-
this.options.watchLoading && this.options.watchLoading.call(this.vm, ...args)
155-
this.vm.$apollo.watchLoading && this.vm.$apollo.watchLoading.call(this.vm, ...args)
156-
this.vm.$apollo.provider.watchLoading && this.vm.$apollo.provider.watchLoading.call(this.vm, ...args)
154+
return this.callHandlers([
155+
this.options.watchLoading,
156+
this.vm.$apollo.watchLoading,
157+
this.vm.$apollo.provider.watchLoading,
158+
], ...args)
157159
}
158160

159161
applyLoadingModifier (value) {

0 commit comments

Comments
 (0)