Skip to content

Commit 687782f

Browse files
committed
docs: last changes for data components
1 parent 13c087f commit 687782f

File tree

1 file changed

+40
-22
lines changed

1 file changed

+40
-22
lines changed

docs/data-components.md

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ sidebarDepth: 3
55

66
# Renderless Data Components
77

8-
There are two new renderless data provider components: `<FeathersVuexFind>` and `<FeathersVuexGet>`. They simplify performing queries against the store and/or the API server. They make the data available inside each component's default slot.
8+
There are three renderless data provider components: `<FeathersVuexFind>`, `<FeathersVuexGet>` and `<FeathersVuexCount>`. They simplify performing queries against the store and/or the API server. They make the data available inside each component's default slot.
99

1010
To see why you might want to use these components, below are two example components that are functionally equivalent.
1111

1212
Here's what it looks like to use the new component:
1313

1414
```html
1515
<template>
16-
<FeathersVuexFind v-slot="{ items: categories }" service="categories" :params="{ query: {} }" watch="params">
16+
<FeathersVuexFind
17+
v-slot="{ items: categories }"
18+
service="categories"
19+
:params="{ query: {} }"
20+
watch="params"
21+
>
1722
<section class="admin-categories">
1823
{{categories}}
1924
</section>
@@ -70,7 +75,12 @@ The `FeathersVuexFind` component retrieves data from the API server, puts it in
7075
### Example
7176

7277
```vue
73-
<FeathersVuexFind v-slot="{ items: users }" service="users" :params="{ query: {} }" watch="query">
78+
<FeathersVuexFind
79+
v-slot="{ items: users }"
80+
service="users"
81+
:params="{ query: {} }"
82+
watch="query"
83+
>
7484
<section>
7585
{{users}}
7686
</section>
@@ -107,7 +117,13 @@ The `FeathersVuexGet` component allows fetching data from directly inside a temp
107117

108118
```html
109119
<template>
110-
<FeathersVuexGet v-slot="{ item: user }" service="users" :id="id" :params="params" :watch="[id, params]">
120+
<FeathersVuexGet
121+
v-slot="{ item: user }"
122+
service="users"
123+
:id="id"
124+
:params="params"
125+
:watch="[id, params]"
126+
>
111127
{{ user }}
112128
</FeathersVuexGet>
113129
</template>
@@ -156,10 +172,10 @@ The `FeathersVuexCount` component allows displaying a count of records. It makes
156172
> **Note:** it only works for services with enabled pagination!
157173
158174
```vue
159-
<FeathersVuexCount v-slot="{ total }" service="users">
160-
<section>
161-
{{users}}
162-
</section>
175+
<FeathersVuexCount v-slot="{ total }" service="users" :params="{ query: {} }">
176+
<span>
177+
{{ total }}
178+
</span>
163179
</FeathersVuexCount>
164180
```
165181

@@ -205,7 +221,7 @@ Vue.component('FeathersVuexCount', FeathersVuexCount)
205221

206222
## Scope Data
207223

208-
When using these components, the scope data will become available to the `FeathersVuexFind` or `FeathersVuexGet` tags. It's accessible using the `v-slot="props"` attribute:
224+
When using these components, the scope data will become available to the `FeathersVuexFind`, `FeathersVuexGet` and `FeathersVuexCount` tags. It's accessible using the `v-slot="props"` attribute:
209225

210226
```html
211227
<FeathersVuexFind v-slot="props" service="categories" :params="{ query: {} }">
@@ -215,8 +231,6 @@ When using these components, the scope data will become available to the `Feathe
215231
</FeathersVuexFind>
216232
```
217233

218-
By default, the following props are available in the scope data:
219-
220234
It's also possible to modify the scope data by passing a function as the `edit-scope` prop. See the example for [modifying scope data](#Modify-the-scope-data)
221235

222236
### Destructuring props
@@ -236,7 +250,11 @@ Use the object destructuring syntax to pull specific variables out of the `v-slo
236250
You can also rename scope props through the Object destructuring syntax. The `v-slot` in the next example shows how to give the items a more-descriptive name:
237251

238252
```html
239-
<FeathersVuexFind v-slot="{ items: categories } service="categories" :params="{ query: {} }"">
253+
<FeathersVuexFind
254+
v-slot="{ items: categories }"
255+
service="categories"
256+
:params="{ query: {} }"
257+
>
240258
<div>
241259
{{categories}}
242260
</div>
@@ -245,7 +263,7 @@ You can also rename scope props through the Object destructuring syntax. The `
245263

246264
## Usage Examples
247265

248-
### A basic find all
266+
#### A basic find all
249267

250268
In this example, only the `service` attribute is provided. There is no `query` nor `id` provided, so no queries are made. So `props.items` in this example returns an empty array.
251269

@@ -257,9 +275,9 @@ In this example, only the `service` attribute is provided. There is no `query` n
257275
</FeathersVuexFind>
258276
```
259277

260-
### Fetch data from the API and the same data from the Vuex store
278+
#### Fetch data from the API and the same data from the Vuex store
261279

262-
This example fetches data from the API server because a query was provided. Internally, this same `query` is used for both the `find` action and the `find` getter. Read other examples to see how to use distinct queries. Be aware that if you use pagination directives like `$skip` or `$limit`, you must use two queries to get the records you desire.
280+
This example fetches data from the API server because a query was provided. Internally, this same `query` is used for both the `find` action and the `find` getter. Read other examples to see how to use distinct queries. Be aware that if you use pagination directives like `$skip` or `$limit`, you must use two queries to get the records you desire.
263281

264282
```html
265283
<FeathersVuexFind v-slot="props" service="todos" :params="{ query: {} }">
@@ -269,7 +287,7 @@ This example fetches data from the API server because a query was provided. Int
269287
</FeathersVuexFind>
270288
```
271289

272-
### Only get data from the local Vuex store
290+
#### Only get data from the local Vuex store
273291

274292
If you've already pulled a bunch of data from the server, you can use the `local` prop to only query the local data:
275293

@@ -281,7 +299,7 @@ If you've already pulled a bunch of data from the server, you can use the `local
281299
</FeathersVuexFind>
282300
```
283301

284-
### Watch the query and re-fetch from the API
302+
#### Watch the query and re-fetch from the API
285303

286304
Sometimes you want to query new data from the server whenever the query changes. Pass an array of attribute names to the `watch` attribute re-query whenever upon change. This example watches the entire query object:
287305

@@ -328,7 +346,7 @@ You can also provide an array of strings to watch multiple properties:
328346
</FeathersVuexFind>
329347
```
330348

331-
### Use a distinct `params` and `fetchParams`
349+
#### Use a distinct `params` and `fetchParams`
332350

333351
In this scenario, the `fetchParams` is be used to grab a larger dataset from the API server (all todos with a matching `userId`). The `params` is used by the `find` getter to display a subset of this data from the store. If the `isComplete` attribute gets set to `true`, only completed todos will be displayed. Since a `fetchParams` is provided, the `watch` strings will be modified internally to watch the `fetchParams` object. This means if you are watching `params.query.userId` and you add a `fetchParams`, the component is smart enough to know you meant `fetchParams.query.userId`. You don't have to rewrite your `watch` attribute after adding a `fetchParams` prop.
334352

@@ -357,7 +375,7 @@ export default {
357375
</script>
358376
```
359377

360-
### Modify the scope data
378+
#### Modify the scope data
361379

362380
The `edit-scope` function allows you to modify the scope before passing it down to the default slot. This feature can be super useful for preparing the data for the template. The `prepareCategories` method in this next example adds two properties to the scope data, which are used to create a nested category structure:
363381

@@ -399,7 +417,7 @@ export default {
399417
</script>
400418
```
401419

402-
### server-side pagination
420+
#### server-side pagination
403421

404422
When you want to use server-side pagination you need to pass the ids from the server to vuex. It can be done by a combination of `params`, `fetchParams` and `editScope` as described below. The `fetchParams`-prop is only computed after items from the server arrived. The ids for the `find` getter as well as the total amount of available values `total` are extracted by the `edit-scope` function and stored in `data`:
405423

@@ -465,7 +483,7 @@ export default {
465483
</script>
466484
```
467485

468-
### Query when certain conditions are met
486+
#### Query when certain conditions are met
469487

470488
Sometimes you only want to query the API server when certain conditions are met. This example shows how to query the API server when the `userSearch` has as least three characters. This property does not affect the internal `find` getter, so the `items` will still update when the `userSearch` property has fewer than three characters, just no API request will be made. The `isFindPending` attribute is used to indicate when data is being loaded from the server.
471489

@@ -509,7 +527,7 @@ export default {
509527
</script>
510528
```
511529

512-
### Use a get request
530+
#### Use a get request
513531

514532
You can perform `get` requests with the `FeathersVuexGet` component and its `id` property. In the next example, when the `selectedUserId` changes, a get request will automatically fetch and display the matching user record. It also shows how to use the `isGetPending` prop to update the UI
515533

0 commit comments

Comments
 (0)