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
@@ -52,51 +52,181 @@ In the above example, any records returned from the server will automatically sh
52
52
53
53
Notice in the above example that using the mixin automatically makes the `serverTasks` available in the template. The mixins automatically setup a few properties in the viewModel based on the camelCased name of the service. You can also provide a `name` attribute to override the defaults:
54
54
55
-
## Options
55
+
## makeFindMixin
56
56
57
-
### for `makeFindMixin` and `makeGetMixin`
57
+
### Options
58
58
59
-
The `makeFindMixin` and `makeGetMixin` utilities share the following options in common. Unique options are found further down.
60
-
61
-
-**service {String}** - **required** the service path. This must match a service that has already been registered with FeathersVuex.
62
-
-**name {String}** - The name to use in all of the dynamically-generated property names. See the section about Dynamically Generated Props
63
-
-**items {String}** - The attribute name to use for the records.
64
-
65
-
-**params {String|Function}** - One of two possible params attributes. (The other is `fetchParams`) When only `params` is provided, it will be used for both the `find` getter and the `find` action. When using server-side pagination, use `fetchParams` for server communciation and the `params` prop for pulling data from the local store. If the params is `null` or `undefined`, the query against both the API will be skipped. The find getter will return an empty array. **Default {String}: `${camelCasedService}Params`** (So, by default, it will attempt to use the property on the component called serviceName + "Params")
59
+
-`service {String|Function}` - **required** the service path. This must match a service that has already been registered with FeathersVuex.
60
+
-**{String}** - The service namespace
61
+
-**{Function}** - Any provided function will become a computed property in the component and will be used to determine its value.
62
+
-`name {String}` - The name to use in all of the dynamically-generated property names. See the section about Dynamically Generated Props
63
+
-`items {String}` - The attribute name to use for the records.
64
+
-`params {String|Function}` - One of two possible params attributes. (The other is `fetchParams`) When only `params` is provided, it will be used for both the `find` getter and the `find` action. When using server-side pagination, use `fetchParams` for server communciation and the `params` prop for pulling data from the local store. If the params is `null` or `undefined`, the query against both the API will be skipped. The find getter will return an empty array. **Default {String}: `${camelCasedService}Params`** (So, by default, it will attempt to use the property on the component called serviceName + "Params")
66
65
-**{String}** - The name of the attribute in the current component which holds or returns the query object.
67
66
-**{Function}** - A provided function will become a computed property in the current component.
67
+
-`watch {String|Array<String>}` - specifies the attributes of the `params` or `fetchParams` to watch. When a watched prop changes, a new request will be made to the API server. Pass 'params' to watch the entire params object. Pass 'params.query.name' to watch the 'name' property of the query. Watch is turned off by default, meaning only one initial request is made. **Default {String}: `${camelCasedService}Params`**
68
+
-**{Boolean}** - If `true`: `[${camelCasedService}Params]` will be watched, else `[]`
69
+
-**{String}** - The name of the component's prop to use as the value. Transformed to an `Array<String>`
70
+
-**{Array<String>}** - Names of the component's prop
71
+
-`fetchParams {String|Function}` - when provided, the `fetchParams` serves as the params for the API server request. When `fetchParams` is used, the `param` attribute will be used against the service's local Vuex store. **Default: undefined**
72
+
-**{String}** - The name of the attribute in the current component which holds or returns the params object.
73
+
-**{Function}** - A provided function will become a computed property in the current component.
74
+
-`queryWhen {Boolean|String|Function}` - the query to the server will only be made when this evaluates to true. **Default: true**
75
+
-**{Boolean}** - As a boolean, the value provided determines whether this is on or off.
76
+
-**{String}** - The name of the component's prop to use as the value.
77
+
-**{Function}** - Any provided function will become a method in the component and will receive the current params object as an argument.
78
+
-`local {Boolean|String|Function}` - when true, will only use the `params` prop to pull data from the local Vuex store. It will disable queries to the API server. The value of `local` will override `queryWhen`. **Default:false**
79
+
-**{Boolean}** - As a boolean, the value provided determines whether this is on or off.
80
+
-**{String}** - The name of the component's prop to use as the value.
81
+
-**{Function}** - Any provided function will become a computed property in the component and will be used to determine its value.
82
+
-`qid {String}` - The "query identifier" ("qid", for short) is used for storing pagination data in the Vuex store. See the service module docs to see what you'll find inside. The `qid` and its accompanying pagination data from the store will eventually be used for cacheing and preventing duplicate queries to the API.
83
+
84
+
### Injected Properties
85
+
86
+
With `makeFindMixin` the following properties will be injected into your component and can become handy to use manually. Since the names of the mixin are basically dynamically generated by the `service` and `name` props you pass. Here the general names to understand what's going on under the hood:
-**watch {String|Array}** - specifies the attributes of the `params` or `fetchParams` to watch. When a watched prop changes, a new request will be made to the API server. Pass 'params' to watch the entire params object. Pass 'params.query.name' to watch the 'name' property of the query. Watch is turned off by default, meaning only one initial request is made. **Default {String}: `${camelCasedService}Params`**
143
+
## makeGetMixin
70
144
71
-
-**fetchParams {String|Function}** - when provided, the `fetchParams` serves as the params for the API server request. When `fetchParams` is used, the `param` attribute will be used against the service's local Vuex store. **Default: undefined**
145
+
### Options
146
+
147
+
-`id {String|Function}` - when performing a `get` request, serves as the id for the request. This is automatically watched, so if the `id` changes, an API request will be made and the data will be updated. If `undefined` or `null`, no request will be made. **Default: undefined**
148
+
-**{String}** - The name of the component's prop to use as the value.
149
+
-**{Function}** - Any provided function will become a computed property in the component and will be used to determine its value.
150
+
-`service {String|Function}` - **required** the service path. This must match a service that has already been registered with FeathersVuex.
151
+
-**{String}** - The service namespace
152
+
-**{Function}** - Any provided function will become a computed property in the component and will be used to determine its value.
153
+
-`name {String}` - The name to use in all of the dynamically-generated property names. See the section about Dynamically Generated Props
154
+
-`item {String}` - The attribute name to use for the record.
155
+
-`params {String|Function}` - One of two possible params attributes. (The other is `fetchParams`) When only `params` is provided, it will be used for both the `find` getter and the `find` action. When using server-side pagination, use `fetchParams` for server communciation and the `params` prop for pulling data from the local store. If the params is `null` or `undefined`, the query against both the API will be skipped. The find getter will return an empty array. **Default {String}: `${camelCasedSingularizedService}Params`** (So, by default, it will attempt to use the property on the component called serviceName + "Params")
156
+
-**{String}** - The name of the attribute in the current component which holds or returns the query object.
157
+
-**{Function}** - A provided function will become a computed property in the current component.
158
+
-`watch {Boolean|String|Array<String>}` - specifies the attributes of the `params` or `fetchParams` to watch. When a watched prop changes, a new request will be made to the API server. Pass 'params' to watch the entire params object. Pass 'params.query.name' to watch the 'name' property of the query. Watch is turned off by default, meaning only one initial request is made. **Default {Array}: `[]`**
159
+
-**{Boolean}** - If `true`: `[${camelCasedService}Params]` will be watched, else `[]`
160
+
-**{String}** - The name of the component's prop to use as the value. Transformed to an `Array<String>`
161
+
-**{Array<String>}** - Names of the component's prop
162
+
-`fetchParams {String|Function}` - when provided, the `fetchParams` serves as the params for the API server request. When `fetchParams` is used, the `param` attribute will be used against the service's local Vuex store. **Default: undefined**
72
163
-**{String}** - The name of the attribute in the current component which holds or returns the params object.
73
164
-**{Function}** - A provided function will become a computed property in the current component.
74
165
75
-
-**queryWhen {Boolean|String|Function}** - the query to the server will only be made when this evaluates to true. **Default: true**
166
+
-`queryWhen {Boolean|String|Function}` - the query to the server will only be made when this evaluates to true. **Default: true**
76
167
-**{Boolean}** - As a boolean, the value provided determines whether this is on or off.
77
168
-**{String}** - The name of the component's prop to use as the value.
78
169
-**{Function}** - Any provided function will become a method in the component and will receive the current params object as an argument.
79
170
80
-
-**local {Boolean|String|Function}** - when true, will only use the `params` prop to pull data from the local Vuex store. It will disable queries to the API server. The value of `local` will override `queryWhen`. **Default:false**
171
+
-`local {Boolean|String|Function}` - when true, will only use the `params` prop to pull data from the local Vuex store. It will disable queries to the API server. The value of `local` will override `queryWhen`. **Default:false**
81
172
-**{Boolean}** - As a boolean, the value provided determines whether this is on or off.
82
173
-**{String}** - The name of the component's prop to use as the value.
83
174
-**{Function}** - Any provided function will become a computed property in the component and will be used to determine its value.
84
175
85
-
### Options for only `makeFindMixin`
176
+
### Injected Properties
86
177
87
-
The `makeFindMixin` has these unique options:
178
+
With `makeGetMixin` the following properties will be injected into your component and can become handy to use manually. Since the names of the mixin are basically dynamically generated by the `service` and `name` props you pass. Here the general names to understand what's going on under the hood:
88
179
89
-
-**qid {String}** - The "query identifier" ("qid", for short) is used for storing pagination data in the Vuex store. See the service module docs to see what you'll find inside. The `qid` and its accompanying pagination data from the store will eventually be used for cacheing and preventing duplicate queries to the API.
-**id {String|Function}** - when performing a `get` request, serves as the id for the request. This is automatically watched, so if the `id` changes, an API request will be made and the data will be updated. If `undefined` or `null`, no request will be made. **Default: undefined**
96
-
-**{String}** - The name of the component's prop to use as the value.
97
-
-**{Function}** - Any provided function will become a computed property in the component and will be used to determine its value.
227
+
## Patterns & Examples
98
228
99
-
## Dynamically Generated Props
229
+
###Dynamically Generated Props
100
230
101
231
Based on what options you provide to each mixin, some dynamically-generated props will be added to the current component. Note that the example below only shows the return values from the computes, not the functions.
It's possible to change the service name on the fly. To do this, pass a function (which becomes a computed property) that returns another string property from the viewModel. Below is an example of how to set that up. The `serviceName` attribute is set to `"videos"`, initially. The `setTimeout` in the `created` method changes the value to `"users"` after three seconds. When the serviceName changes, the users service is queried automatically. The `items` property will then update to be the newly fetched users instead of the video records that it contained before. The `items` option is used to rename the items to something more generic.
The `makeFindMixin` in `[email protected]` features a great new, high performance, fall-through cacheing feature, which only uses a single query! Read the service module documentation for details of how it works under the hood. It really makes easy work of high-performance pagination. To use the pagination, provide `$limit` and `$skip` attributes in `params.query`. This is exactly the same way you would normally do with any FeathersJS query. So this is completely transparent to how you'd normally do it.
239
369
@@ -290,7 +420,7 @@ export default {
290
420
291
421
In the above example, since we've enabled the `watch` attribute on the makeFindMixin, every time the params change, the query will run again. `feathers-vuex` will keep track of the queries and the pages that are visited, noting which records are returned on each page. When a page is revisited, the data in the store will *immedately* display to the user. The query will (by default) go out to the API server, and data will be updated in the background when the response arrives.
292
422
293
-
## Debouncing requests
423
+
###Debouncing requests
294
424
295
425
What happens when a query with a watcher is attached to an attribute that might change rapidly? A lot of API requests can get sent in succession. If too many are sent, some of them will start to fail (a.k.a. bounce). The `makeFindMixin` has a built-in utility for debouncing requests. Enabling it makes it so requests only are sent after a specific amount of time has passed. To enable it, pass a `debounce` attribute in the `params`, as shown in the next example.
296
426
@@ -366,7 +496,7 @@ We also added a `$regex` search to the params. This is a MongoDB feature, which
366
496
367
497
Feel free to make a PR for using something else that could be useful to the community! We love those!
368
498
369
-
## Enabling live lists with pagination
499
+
###Enabling live lists with pagination
370
500
371
501
The new fall-through cacheing pagination does not currently support live sorting of lists. This means that when a new record arrives from the database, it doesn't automatically get sorted into the correct page and shuffle the other records around it. The lists will update as the user navigates to previous/next pages. Coming up with a solution for this will be a top priority after 2.x ships. In the meantime, here are some alternatives.
372
502
@@ -487,7 +617,7 @@ export default {
487
617
</template>
488
618
```
489
619
490
-
## Debugging the makeFindMixin
620
+
###Debugging the makeFindMixin
491
621
492
622
**Important: For the built in pagination features to work, you must not directly manipulate the `context.params` object in any hooks.**
0 commit comments