You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -128,7 +128,7 @@ Let's look at the functionality that each one provides:
128
128
-`servicePath` is the FeathersJS service path that is used by the current model. This is mostly only useful for debugging.
129
129
-`isFindPending` is a boolean that indicates if there is an active query. It is set to `true` just before each outgoing request. It is set to `false` after the response returns. Bind to it in the UI to show an activity indicator to the user.
130
130
-`haveBeenRequestedOnce` is a boolean that is set to `true` immediately before the first query is sent out. It remains true throughout the life of the component. This comes in handy for first-load scenarios in the UI.
131
-
-`haveLoadedOnce` is a boolean that is set to true after the first API response. It remains `true` for the life of the component. This also comes in handy for first-load scenarios in the UI.
131
+
-`haveLoaded` is a boolean that is set to true after the first API response. It remains `true` for the life of the component. This also comes in handy for first-load scenarios in the UI.
132
132
-`isLocal` is a boolean that is set to true if this data is local only.
133
133
-`qid` is currently the primary `qid` provided in params. It might become more useful in the future.
134
134
-`debounceTime` is the current number of milliseconds used as the debounce interval.
@@ -157,7 +157,7 @@ import { useFind } from 'feathers-vuex'
157
157
exportdefault {
158
158
name:'UserGuide',
159
159
setup(props, context) {
160
-
const { Todo } =context.root.$FeathersVuex.spark
160
+
const { Todo } =context.root.$FeathersVuex.api
161
161
162
162
consttodosParams=computed(() => {
163
163
return {
@@ -196,7 +196,197 @@ The `useGet` utility is still being built. Docs will be written when it becomes
196
196
197
197
### Returned Attributes
198
198
199
-
## Pairing `useFind` with `useGet`
199
+
## Pattens: `useFind` with `useGet`
200
+
201
+
### Simultaneous Queries
202
+
203
+
Let's look at an example where we have two separate tables and we want live-queried lists for both of them. This example will show a component for a doctor's office that pulls up a patient by `id` using `useGet` then retrieves all of the patient's `appointments` using `useFind`.
204
+
205
+
```html
206
+
<template>
207
+
<div>
208
+
<div>{{ patient.name }}</div>
209
+
210
+
<liv-for="appointment in appointments":key="appointment._id">
// Get all of the appointments belonging to the current patient
235
+
constappointmentsParams=computed(() => {
236
+
return {
237
+
query: {
238
+
userId:props.id,
239
+
$sort: { date:-1 }
240
+
}
241
+
}
242
+
})
243
+
const { items:appointments } =useFind({
244
+
model: Appointment,
245
+
params: appointmentsParams
246
+
})
247
+
248
+
return {
249
+
patient,
250
+
appointments
251
+
}
252
+
}
253
+
}
254
+
```
255
+
256
+
### Deferring Queries
257
+
258
+
In the previous example, the requests for the `patient` and `appointments` are made at the same time because the user's `id` is available, already. What if we were required to load `appointments` after the `patient` record finished loading? We could change the `appointmentsParams` to return `null` until the `patient` record becomes available, as shown in the following example:
259
+
260
+
```html
261
+
<template>
262
+
<div>
263
+
<div>{{ patient.name }}</div>
264
+
265
+
<li v-for="appointment in appointments":key="appointment._id">
266
+
{{ appointment.date }}
267
+
</li>
268
+
269
+
<div v-if="!appointments.length && haveLoaded">
270
+
No appointments have been scheduled forthis patient.
Reviewing the above snippet, while there is no `patient` record, the `appointmentsParams` computed property returns `null` at comment `(1)`. This will prevent any query from going out to the API server.
322
+
323
+
Once the `patient` has loaded, the full params object is returned at comment `(2)`. This allows the `useFind` utility to make the request.
324
+
325
+
### Showing Loading State
326
+
327
+
This next example builds on the previous one and adds loading state for both the `patient` and the `appointments`.
328
+
329
+
```html
330
+
<template>
331
+
<div>
332
+
<div v-if="isPatientLoading">Loading</div>
333
+
<div v-else>{{ patient.name }}</div>
334
+
335
+
<li v-for="appointment in appointments":key="appointment._id">
336
+
{{ appointment.date }}
337
+
</li>
338
+
339
+
<div v-if="!appointments.length && haveLoaded">
340
+
No appointments have been scheduled forthis patient.
0 commit comments