Skip to content

Commit c620bba

Browse files
committed
docs: add per-instance pending status info
1 parent e3d5483 commit c620bba

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

docs/model-classes.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ const todo = new Todo({ description: 'Do something!' })
339339

340340
The examples above show instantiating a new Model instance without an `id` field. In this case, the record is not added to the Vuex store. If you instantiate a record **with an `id`** field, it **will** get added to the Vuex store. *Note: This field is customizable using the `idField` option for this service.*
341341

342-
Now that we have Model instances, let's take a look at the functionality they provide. Each instance will include the following methods:
342+
Now that we have Model instances, let's take a look at the functionality they provide.
343+
344+
Each instance will include the following methods:
343345

344346
- `.save()`
345347
- `.create()`
@@ -349,6 +351,15 @@ Now that we have Model instances, let's take a look at the functionality they pr
349351
- `.commit()`
350352
- `.reset()`
351353

354+
and the following readonly attributes:
355+
356+
- `isCreatePending` - `create` is currently pending on this model
357+
- `isUpdatePending` - `update` is currently pending on this model
358+
- `isPatchPending` - `patch` is currently pending on this model
359+
- `isRemovePending` - `remove` is currently pending on this model
360+
- `isSavePending` - Any of `create`, `update` or `patch` is currently pending on this model
361+
- `isPending` - Any method is currently pending on this model
362+
352363
*Remember, if a record already has an attribute with any of these method names, it will be overwritten with the method.*
353364

354365
These methods give access to many of the store `actions` and `mutations`. Using Model instances, you no longer have to use `mapActions` for `create`, `patch`, `update`, or `remove`. You also no longer have to use `mapMutations` for `createCopy`, `commitCopy`, or `resetCopy`.

docs/service-plugin.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ Each service comes loaded with the following default state:
156156
errorOnCreate: undefined,
157157
errorOnUpdate: undefined,
158158
errorOnPatch: undefined,
159-
errorOnRemove: undefined
159+
errorOnRemove: undefined,
160+
161+
isIdCreatePending: [],
162+
isIdUpdatePending: [],
163+
isIdPatchPending: [],
164+
isIdRemovePending: [],
160165
}
161166
```
162167

@@ -193,6 +198,13 @@ The following state attribute will be populated with any request error, serializ
193198
- `errorOnPatch {Error}`
194199
- `errorOnRemo {Error}`
195200

201+
The following state attributes allow you to bind to the pending state of requests *per item ID*
202+
203+
- `isIdCreatePending {Array}` - Contains `id` if there's a pending `create` request for `id`.
204+
- `isIdUpdatePending {Array}` -Contains `id` if there's a pending `update` request for `id`.
205+
- `isIdPatchPending {Array}` - Contains `id` if there's a pending `patch` request for `id`.
206+
- `isIdRemovePending {Array}` - Contains `id` if there's a pending `remove` request for `id`.
207+
196208
## Service Getters
197209

198210
Service modules include the following getters:
@@ -206,6 +218,15 @@ Service modules include the following getters:
206218
- `id {Number|String}` - the id of the data to be retrieved by id from the store.
207219
- `params {Object}` - an object containing a Feathers `query` object.
208220

221+
The following getters ease access to per-instance pending status
222+
223+
- `isCreatePendingById(id) {Function}` - Check if `create` is pending for `id`
224+
- `isUpdatePendingById(id) {Function}` - Check if `update` is pending for `id`
225+
- `isPatchPendingById(id) {Function}` - Check if `patch` is pending for `id`
226+
- `isRemovePendingById(id) {Function}` - Check if `remove` is pending for `id`
227+
- `isSavePendingById(id) {Function}` - Check if `create`, `update`, or `patch` is pending for `id`
228+
- `isPendingById(id) {Function}` - Check if `create`, `update`, `patch` or `remove` is pending for `id`
229+
209230
## Service Mutations
210231

211232
The following mutations are included in each service module.
@@ -262,7 +283,9 @@ Clears all data from `ids`, `keyedById`, and `currentId`
262283
The following mutations are called automatically by the service actions, and will rarely, if ever, need to be used manually.
263284

264285
- `setPending(state, method)` - sets the `is${method}Pending` attribute to true
286+
- `setIdPending(state, { method, id })` - adds `id` to `isId${method}Pending` array
265287
- `unsetPending(state, method)` - sets the `is${method}Pending` attribute to false
288+
- `unsetIdPending(state, { method, id })` - removes `id` from `isId${method}Pending` array
266289

267290
### Mutations for Managing Errors
268291

0 commit comments

Comments
 (0)