Skip to content

Commit f6207da

Browse files
author
Guillaume Chau
committed
Manual mode
1 parent 65f9088 commit f6207da

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ These are the available advanced options you can use:
408408
- `error(error)` is a hook called when there are errors, `error` being an Apollo error object with either a `graphQLErrors` property or a `networkError` property.
409409
- `loadingKey` will update the component data property you pass as the value. You should initialize this property to `0` in the component `data()` hook. When the query is loading, this property will be incremented by 1 and as soon as it no longer is, the property will be decremented by 1. That way, the property can represent a counter of currently loading queries.
410410
- `watchLoading(isLoading, countModifier)` is a hook called when the loading state of the query changes. The `countModifier` parameter is either equal to `1` when the query is now loading, or `-1` when the query is no longer loading.
411+
- `manual` is a boolean that disable the automatic property update. You then need to specify a `result` callback (see example below).
411412

412413

413414
```javascript
@@ -466,6 +467,20 @@ If you use `ES2015`, you can also write the `update` like this:
466467
update: data => data.ping
467468
```
468469

470+
Manual mode example:
471+
472+
```javascript
473+
{
474+
query: gql`...`,
475+
manual: true,
476+
result ({ data, loading }) {
477+
if (!loading) {
478+
this.items = data.items
479+
}
480+
},
481+
}
482+
```
483+
469484
### Reactive Query Example
470485

471486
Here is a reactive query example using polling:

src/smart-apollo.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,21 @@ export class SmartQuery extends SmartApollo {
217217
this.loadingDone()
218218
}
219219

220+
const hasResultCallback = typeof this.options.result === 'function'
221+
220222
if (typeof data === 'undefined') {
221223
// No result
222224
} else if (typeof this.options.update === 'function') {
223225
this.vm[this.key] = this.options.update.call(this.vm, data)
224226
} else if (data[this.key] === undefined) {
225227
console.error(`Missing ${this.key} attribute on result`, data)
226-
} else {
228+
} else if (!this.options.manual) {
227229
this.vm[this.key] = data[this.key]
230+
} else if (!hasResultCallback) {
231+
console.error(`${this.key} query must have a 'result' hook in manual mode`)
228232
}
229233

230-
if (typeof this.options.result === 'function') {
234+
if (hasResultCallback) {
231235
this.options.result.call(this.vm, result)
232236
}
233237
}

0 commit comments

Comments
 (0)