Skip to content

Commit 0cdc40d

Browse files
authored
docs: comprehensive documentation updates (#117)
1 parent 5403ea7 commit 0cdc40d

File tree

7 files changed

+305
-168
lines changed

7 files changed

+305
-168
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121

2222
Vuex ORM Axios plugin adds smooth integration between API requests and [Vuex ORM](https://github.com/vuex-orm/vuex-orm) data persistence through the awesome [axios](https://github.com/axios/axios).
2323

24+
If you use axios with Vuex ORM, you may find handling requests can become an arduous and repetitive process. This plugin bridges Vuex ORM and axios and brings a unified process to perform requests and persist response data with ease.
25+
2426
```js
25-
// Model API request...
27+
// Example usage: fetch users and persist to store.
2628
User.api().get('/api/users')
2729
```
2830

docs/README.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
# Vuex ORM Axios
22

3-
Vuex ORM Axios plugin adds smooth integration between API requests and [Vuex ORM](https://github.com/vuex-orm/vuex-orm) data persistence through the awesome [Axios](https://github.com/axios/axios).
3+
Vuex ORM Axios plugin adds smooth integration between API requests and [Vuex ORM](https://github.com/vuex-orm/vuex-orm) data persistence through the awesome [axios](https://github.com/axios/axios).
4+
5+
If you use axios with Vuex ORM, you may find handling requests can become an arduous and repetitive process. This plugin bridges Vuex ORM and axios and brings a unified process to perform requests and persist response data with ease.
6+
7+
```js
8+
// Example usage: fetch users and persist to store.
9+
User.api().get('/api/users')
10+
```
11+
412

513
## Sponsors
614

715
Vuex ORM is sponsored by awesome folks. Big love to all of them from the whole Vuex ORM community :two_hearts:
816

9-
### Super Love Sponsors
17+
#### Super Love Sponsors
1018

1119
<br>
1220

@@ -22,6 +30,9 @@ Vuex ORM is sponsored by awesome folks. Big love to all of them from the whole V
2230
<a href="https://github.com/somazx">
2331
<img src="https://avatars0.githubusercontent.com/u/7306?s=460&v=4" alt="Andy Koch" width="88" style="border-radius: 8px;">
2432
</a>
33+
<a href="https://github.com/dylancopeland">
34+
<img src="https://avatars1.githubusercontent.com/u/99355?s=460&v=4" alt="Dylan Copeland" width="88" style="border-radius: 8px;">
35+
</a>
2536

2637
#### Big Love Sponsors
2738

@@ -44,26 +55,32 @@ Vuex ORM is sponsored by awesome folks. Big love to all of them from the whole V
4455
<a href="https://github.com/bpuig">
4556
<img src="https://avatars3.githubusercontent.com/u/22938625?s=460&v=4" alt="bpuig" width="48" style="border-radius: 8px;">
4657
</a>
58+
<a href="https://github.com/robokozo">
59+
<img src="https://avatars2.githubusercontent.com/u/1719221?s=400&u=b5739798ee9a3d713f5ca3bd3d6a086c13d229a3&v=4" alt="John" width="48" style="border-radius: 8px;">
60+
</a>
61+
4762

4863
## Table of Contents
4964

5065
- Guide
51-
- [Installation](/guide/installation.md)
52-
- [Setup](/guide/setup.md)
53-
- [Usage](/guide/usage.md)
54-
- [Configurations](/guide/configurations.md)
55-
- [Custom Actions](/guide/custom-actions.md)
56-
- [Sponsors](/guide/sponsors)
66+
- [Installation](/guide/installation.md)
67+
- [Setup](/guide/setup.md)
68+
- [Usage](/guide/usage.md)
69+
- [Configurations](/guide/configurations.md)
70+
- [Custom Actions](/guide/custom-actions.md)
71+
- [Sponsors](/guide/sponsors)
5772
- API
58-
- [Model](/api/model.md)
59-
- [Request](/api/request.md)
60-
- [Response](/api/response.md)
73+
- [Model](/api/model.md)
74+
- [Request](/api/request.md)
75+
- [Response](/api/response.md)
76+
6177

6278
## Questions & Discussions
6379

6480
Join us on our [Slack Channel](https://join.slack.com/t/vuex-orm/shared_invite/enQtNDQ0NjE3NTgyOTY2LTc1YTI2N2FjMGRlNGNmMzBkMGZlMmYxOTgzYzkzZDM2OTQ3OGExZDRkN2FmMGQ1MGJlOWM1NjU0MmRiN2VhYzQ) for any questions and discussions.
6581

66-
Although there is the Slack Channel, do not hesitate to open an [issue](https://github.com/vuex-orm/vuex-orm/issues) for any question you might have. We're always more than happy to hear any feedback, and we don't care what kind of form they are.
82+
Although there is the Slack Channel, do not hesitate to open an [issue](https://github.com/vuex-orm/plugin-axios/issues) for any question you might have. We're always more than happy to hear any feedback, and we don't care what kind of form they are.
83+
6784

6885
## Plugins
6986

@@ -74,10 +91,4 @@ Vuex ORM can be extended via plugins to add additional features. Here is a list
7491
- [Vuex ORM Change Flags](https://github.com/vuex-orm/plugin-change-flags) - Vuex ORM plugin for adding IsDirty / IsNew flags to model entities.
7592
- [Vuex ORM Soft Delete](https://github.com/vuex-orm/plugin-soft-delete) – Vuex ORM plugin for adding soft delete feature to model entities.
7693

77-
## Resources
78-
79-
- [Vue](https://vuejs.org)
80-
- [Vuex](https://vuex.vuejs.org)
81-
- [Vuex ORM](https://vuex-orm.github.io/vuex-orm/)
82-
83-
You may find a list of awesome things related to Vuex ORM at [Awesome Vuex ORM](https://github.com/vuex-orm/awesome-vuex-orm).
94+
You can find a list of awesome things related to Vuex ORM at [Awesome Vuex ORM](https://github.com/vuex-orm/awesome-vuex-orm).

docs/guide/configurations.md

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Configurations
22

3-
You may configure many options in Vuex ORM Axios and its underlining Axios instance. There are 3 places to set options.
3+
Vuex ORM Axios plugin comes with a wealth of options to control request behavior. These options can be configured in three common places:
44

5-
- Global Configuration
6-
- Model Configuration
7-
- Request Configuration
5+
- **Globally** - options can defined during installation
6+
- **Model** - options can be defined on a per-model basis
7+
- **Request** - options can be defined on a per-request basis
88

9-
Global Configuration can be defined at the installation process by passing the option as the second argument of `VuexORM.use` method.
9+
Any axios options are permitted alongside any plugin options. Options are inherited in the same order, i.e. Global configuration is merged and preceded by Model configuration which is then merged and preceded by any Request configuration.
10+
11+
### Global Configuration
12+
13+
Options can be defined during plugin installation by passing an object as the second argument of the Vuex ORM `use()` method. At minimum, the axios instance is required while any other option is entirely optional.
14+
15+
The following example configures the plugin with an axios instance (required), the `baseURL` option, and some common `headers` that all requests will inherit:
1016

1117
```js
1218
import axios from 'axios'
@@ -20,7 +26,11 @@ VuexORM.use(VuexORMAxios, {
2026
})
2127
```
2228

23-
You may define configuration at the Model level too. To do so, define `static apiConfig` property to the Model.
29+
### Model Configuration
30+
31+
Options can be defined on models by setting the static `apiConfig` property. This is an object where you may configure model-level request configuration.
32+
33+
The following example configures a model with common `headers` and `baseURL` options:
2434

2535
```js
2636
import { Model } from '@vuex-orm/core'
@@ -42,7 +52,11 @@ class User extends Model {
4252
}
4353
```
4454

45-
Finally, you can pass configuration when making the api call.
55+
### Request Configuration
56+
57+
Options can be defined on a per-request basis. These options will inherit any global and model configurations which are subsequently passed on to the request.
58+
59+
The following example configures a request with common `headers` and `baseURL` options:
4660

4761
```js
4862
User.api().get('/api/users', {
@@ -51,17 +65,21 @@ User.api().get('/api/users', {
5165
})
5266
```
5367

54-
The lower level configuration will overwrite a higher level of configs. Which means that the Request Config will overwrite Model Config, and Model Config will overwrite Global Config.
68+
Request configurations vary depending on the type of request being made. Please refer to the [Usage Guide](usage) to read more.
69+
5570

5671
## Available Options
5772

58-
All Axios configurations are available. For those, please refer to [the Axios documentation](https://github.com/axios/axios#request-config). In addition to Axios options, Vuex ORM Axios takes few more options specific to the plugin usage.
73+
In addition to [axios request options](https://github.com/axios/axios#request-config), the plugin can be configured with the following options:
74+
75+
### `dataKey`
5976

60-
### dataKey
77+
- **Type**: `string`
78+
- **Default**: `undefined`
6179

62-
- **`dataKey?: string | null`**
80+
This option will inform the plugin of the resource key your elements may be nested under in the response body.
6381

64-
This option will define which key to look for when persisting response data. Let's say your response from the server looks like below.
82+
For example, your response body may be nested under a resource key called `data`:
6583

6684
```js
6785
{
@@ -72,52 +90,33 @@ All Axios configurations are available. For those, please refer to [the Axios do
7290
}
7391
}
7492
```
75-
76-
In this case, data persistent to the store will probably fail, since actual data is inside the `data` key, but Vuex ORM Axios is going to insert whole object including `ok` property.
77-
78-
For these situations, you can use `dataKey` property to specify which key to look for data.
93+
94+
The following example sets the `dataKey` to `data` as this is the resource key which contains the required data for the model schema.
7995

8096
```js
8197
User.api().get('/api/users', {
8298
dataKey: 'data'
8399
})
84100
```
85101

86-
With the above config, the data inside `data` key will be inserted to the store.
87-
88-
> **NOTE:** When `dataTransformer` key is set, this option will be ignored.
89-
90-
### dataTransformer
91-
92-
- **`dataTransformer?: ((response: AxiosResponse) => Record | Record[])`**
102+
The plugin will pass all the data within the data object to Vuex ORM which can then be successfully persisted to the store.
93103

94-
This option will let you transform the response before persisting it to the store. Let's say your response from the server looks like below.
95-
96-
```js
97-
{
98-
ok: true,
99-
record: {
100-
id: 1,
101-
name: 'John Doe'
102-
}
103-
}
104-
```
104+
::: warning
105+
This option is ignored when using the `dataTransformer` option.
106+
:::
105107

106-
You can use `dataTransform` property to specify how you want to transform the data. The whole Axios response will be passed as callback argument.
108+
### `dataTransformer`
107109

108-
```js
109-
User.api().get('/api/users', {
110-
dataTransformer: (response) => {
111-
return response.data.record
112-
}
113-
})
114-
```
110+
- **Type**: `(response: AxiosResponse) => Array | Object`
111+
- **Default**: `undefined`
115112

116-
With the above config, the data inside `record` key will be inserted to the store.
113+
This option will let you intercept and transform the response before persisting it to the store.
114+
115+
The method will receive a [Response](usage.md#handling-responses) object allowing you to access response properties such as response headers, as well as manipulate the data as you see fit.
117116

118-
It is very useful when you need to transform a given response to be handle by Vuex ORM. For instance, if you format your response with the [JSON:API specs](https://jsonapi.org/), you can transform your response with this callback.
117+
Any method defined must return data to pass on to Vuex ORM.
119118

120-
You can always use object destructuring to get specific properties from the response object too.
119+
You can also use object destructuring to get specific properties from the response object.
121120

122121
```js
123122
User.api().get('/api/users', {
@@ -130,38 +129,39 @@ All Axios configurations are available. For those, please refer to [the Axios do
130129
})
131130
```
132131

133-
> **NOTE:** When `dataTransformer` key is set, `dataKey` option will be ignored.
132+
::: warning
133+
Using the `dataTransformer` option will ignore any `dataKey` option.
134+
:::
134135

135-
### save
136+
- **See also**: [Transforming Data](usage.md#transforming-data)
136137

137-
- **`save: boolean = true`**
138+
### `save`
138139

139-
This option will determine whether to store the response data to the store or not. If you set this value to `false`, the response data will not be persisted to the store. In that case, the `entities` property at the Response object will become null.
140+
- **Type**: `boolean`
141+
- **Default**: `true`
140142

141-
```js
142-
User.api().get('/api/users', {
143-
save: false
144-
})
145-
```
143+
This option will determine whether Vuex ORM should persist the response data to the store or not.
144+
145+
By setting this option to `false`, the response data will not be persisted and you will have to handle persistence alternatively. The `entities` property in the [Response](usage.md#handling-responses) object will also be `null` since it will no longer be persisting data automatically.
146146

147-
### delete
147+
- **See also**: [Deferring Persistence](usage.md#deferring-persistence)
148148

149-
- **`delete?: string | number | (model: Model) => boolean`**
149+
### `delete`
150150

151-
When this option is defined, the matching record will be deleted from the store after the api call. Usually, you need to set this when calling api to delete a record. When this option is set, the response data will not be persisted even if the `save` option is set to true.
151+
- **Type**: `string | number | (model: Model) => boolean`
152+
- **Default**: `undefined`
152153

153-
```js
154-
User.api().delete('/api/users', {
155-
delete: 42
156-
})
157-
```
154+
This option is primarily used with delete requests. It's argument signature is identical to the [Vuex ORM delete](https://vuex-orm.org/guide/data/deleting) method by which a primary key can be set as the value, or passing a predicate function. The corresponding record will be removed from the store after the request is made.
155+
156+
Setting this option will ignore any `save` options you may have set and therefore persistence is not possible when using this option.
158157

159-
Well, you may wonder having to manually specify what record to be deleted is a bit redundant. However, without this option, Vuex ORM Axios wouldn't know what records should be deleted because it can't rely on the response data.
158+
- **See also**: [Delete Requests](usage.md#delete-requests)
160159

161-
We're open to any suggestions and recommendations to improve the "delete" functionality. Please feel free to open an issue on GitHub!
160+
### `actions`
162161

163-
### actions
162+
- **Type**: `Object`
163+
- **Default**: `{}`
164164

165-
- **`actions?: { [name: string]: ActionObject | ActionFunction }`**
165+
This option allows for your own predefined api methods.
166166

167-
You can define custom actions in here. Please refer to the [Custom Actions](custom-actions) page to learn more about it.
167+
Please refer to the [Custom Actions](custom-actions) documentation to learn more.

docs/guide/installation.md

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,66 @@
11
# Installation
22

3-
You can install Vuex ORM Axios via NPM, Yarn, or download it directly. Remember since Vuex ORM Axios is a plugin of [Vuex ORM](https://github.com/vuex-orm/vuex-orm), you need to install Vuex ORM and Vuex alongside with Vuex ORM Axios. Also, Vuex ORM Axios requires manually passing Axios Instance. Don't forget to install Axios as well.
3+
You can install Vuex ORM Axios via NPM, Yarn, or download it directly. This is a plugin for Vuex ORM, therefore you must ensure [Vuex ORM](https://vuex-orm.org/guide/prologue/installation) and [axios](https://github.com/axios/axios#installing) are installed.
44

55
## NPM
66

7-
```console
8-
$ npm install axios vue vuex @vuex-orm/core @vuex-orm/plugin-axios --save
7+
```bash
8+
npm install @vuex-orm/plugin-axios --save
99
```
1010

1111
## Yarn
1212

13-
```console
14-
$ yarn add axios vue vuex @vuex-orm/core @vuex-orm/plugin-axios
13+
```bash
14+
yarn add @vuex-orm/plugin-axios
1515
```
1616

1717
## Direct Download / CDN
1818

19-
[https://unpkg.com/@vuex-orm/plugin-axios](https://unpkg.com/@vuex-orm/plugin-axios)
19+
[](https://unpkg.com/@vuex-orm/plugin-axios)
2020

21-
[Unpkg.com](https://unpkg.com) provides NPM-based CDN links. The above link always points to the latest release on NPM. You can also use a specific version/tag via URLs like `https://unpkg.com/@vuex-orm/plugin-axios`.
21+
[Unpkg.com](https://unpkg.com) provides NPM-based CDN links. Simply download and include with a script tag.
2222

23-
Include Vuex ORM Axios from an HTML script.
23+
For development environments, testing and learning purposes, you can use the latest uncompressed version with:
2424

2525
```html
2626
<script src="https://unpkg.com/@vuex-orm/plugin-axios"></script>
27+
```
28+
29+
For production, it's recommended to link to a specific version number and build to avoid unexpected breakage from newer versions:
30+
31+
```html
32+
<script src="https://unpkg.com/@vuex-orm/[email protected]/dist/vuex-orm-axios.min.js"></script>
33+
34+
```
2735

28-
<!-- For the minified version -->
29-
<script src="https://unpkg.com/@vuex-orm/plugin-axios/dist/vuex-orm.min.js"></script>
36+
See [Release Notes](https://github.com/vuex-orm/plugin-axios/releases) for available versions.
37+
38+
If you are using native ES Modules, there is also an ESM compatible build:
39+
40+
```html
41+
<script type="module">
42+
import VuexORMAxios from 'https://unpkg.com/@vuex-orm/plugin-axios/dist/vuex-orm-axios.esm.js'
43+
</script>
3044
```
3145

46+
### Build Variants
47+
48+
In the `dist/` directory of the NPM package you will find many different builds. Each of them have their use depending on your build environment and may help to reduce bundle sizes.
49+
50+
| | URL |
51+
|----------------------------|:---------------------------------------------------------------------------------------------------------------------|
52+
| Development (uncompressed) | [vuex-orm-axios.js](https://unpkg.com/@vuex-orm/plugin-axios) |
53+
| Production (compressed) | [vuex-orm-axios.min.js](https://unpkg.com/@vuex-orm/plugin-axios/dist/vuex-orm-axios.min.js) |
54+
| CommonJS | [vuex-orm-axios.common.js](https://unpkg.com/@vuex-orm/plugin-axios/dist/vuex-orm-axios.common.js) |
55+
| ES Module | [vuex-orm-axios.esm.js](https://unpkg.com/@vuex-orm/plugin-axios/dist/vuex-orm-axios.esm.js) |
56+
3257
## Dev Build
3358

34-
You have to clone directly from GitHub and build Vuex yourself if you want to use the latest dev build.
59+
The built files in `/dist` folder are only checked-in during releases. To use the latest source code on GitHub, you will have to run a build yourself.
3560

36-
```console
37-
$ git clone https://github.com/vuex-orm/plugin-axios.git node_modules/@vuex-orm/plugin-axios
38-
$ cd node_modules/@vuex-orm/plugin-axios
39-
$ npm install
40-
$ npm run build
61+
```bash
62+
# cd /path/to/project
63+
git clone https://github.com/vuex-orm/plugin-axios.git node_modules/@vuex-orm/plugin-axios
64+
cd node_modules/@vuex-orm/plugin-axios
65+
yarn && yarn build
4166
```

0 commit comments

Comments
 (0)