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
Copy file name to clipboardExpand all lines: README.md
+31-33Lines changed: 31 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,14 @@ A module to access JSONAPI data from an API, using a Vuex store, restructured to
6
6
7
7
## Features
8
8
9
-
* Creates a [Vuex](https://vuex.vuejs.org/) module to store API data.
10
-
* High-level methods to wrap common RESTful operations (GET, POST, PUT, DELETE).
11
-
* Restructures/normalizes data, making record handling easier.
12
-
* Makes fetching related objects easy.
13
-
* Relationships can be followed and expanded into records automatically (recursively).
14
-
* Uses [Axios](https://github.com/axios/axios) (or your own axios-like module) as the HTTP client.
15
-
* Uses [jsonpath](https://github.com/dchester/jsonpath) for filtering when getting objects from the store.
16
-
* Records the status of actions (LOADING, SUCCESS, ERROR).
9
+
- Creates a [Vuex](https://vuex.vuejs.org/) module to store API data.
10
+
- High-level methods to wrap common RESTful operations (GET, POST, PUT, DELETE).
11
+
- Restructures/normalizes data, making record handling easier.
12
+
- Makes fetching related objects easy.
13
+
- Relationships can be followed and expanded into records automatically (recursively).
14
+
- Uses [Axios](https://github.com/axios/axios) (or your own axios-like module) as the HTTP client.
15
+
- Uses [jsonpath](https://github.com/dchester/jsonpath) for filtering when getting objects from the store.
16
+
- Records the status of actions (LOADING, SUCCESS, ERROR).
17
17
18
18
## Setup
19
19
@@ -56,13 +56,13 @@ There are 4 actions (with aliases): `get` (`fetch`), `post` (`create`), `patch`
56
56
57
57
These actions take 2 arguments: the path/object to be acted on, and an (optional) [`axios` config object](https://github.com/axios/axios#request-config). The first argument is an object containing [restructured data](#restructured-data).
58
58
59
-
*Note* - Since the `dispatch` method can only accept a single argument, if both arguments are used, the argument must be an array.
59
+
_Note_ - Since the `dispatch` method can only accept a single argument, if both arguments are used, the argument must be an array.
60
60
61
61
The first argument is an object containing [restructured data](#restructured-data). Actions which take no `data` argument apart from the record (`get` and `delete`) can also accept a URL to fetch (relative to `axios``baseURL` (if set) leading slash is optional). This means you don't need to create an 'empty' restructured data object to get or delete a record. Some examples:
*Note* - in many cases you may prefer to use the jsonapi server-side `include` option to get data on relationships included in your original query. (See `Related Items`).
101
+
_Note_ - in many cases you may prefer to use the jsonapi server-side `include` option to get data on relationships included in your original query. (See `Related Items`).
102
102
103
103
Like the RESTful actions, this takes 2 arguments - the URL/object to be acted on, and an axios config object. It returns a deeply nested restructured tree - `relationship -> type -> id -> data`.
104
104
105
-
*Note* - `getRelated` only works on specific items, not collections.
105
+
_Note_ - `getRelated` only works on specific items, not collections.
By default the `get` action and getter are both configured to follow and expand out relationships recursively, if they are provided as `data` entries (i.e. `{type: 'widget', id: '1'}`).
241
239
242
-
*Note* - If using the `action` you may wish to also set the `include` parameter on the server query to include the relationships you are interested in. Any records returned in the `included` section of the jsonapi data will be automatically added to the store.
240
+
_Note_ - If using the `action` you may wish to also set the `include` parameter on the server query to include the relationships you are interested in. Any records returned in the `included` section of the jsonapi data will be automatically added to the store.
243
241
244
-
For any relationships where the related item is already in the store, this is added to the returned object(s) in `obj['_jv']['rels'][rel_name]`. For items with a single relationship, the object is placed directly under the `rel_name` - for mutiple items, they are indexed by id:
242
+
For any relationships where the related item is already in the store, this is added to the returned object(s) in `obj['_jv']['rels'][relName]`. For items with a single relationship, the object is placed directly under the `relName` - for mutiple items, they are indexed by id:
245
243
246
244
```
247
245
// Assuming the store is as follows:
@@ -292,10 +290,10 @@ let item1 = this.$store.getters['jv/get']('widget/1')
292
290
}
293
291
294
292
// This can then be accessed as:
295
-
let related_item_name = item1._jv.rels.parts.name
293
+
item1._jv.rels.parts.name
296
294
297
295
// Or if there were multiple related items as:
298
-
let related_item2_name = item1._jv.rels.parts.2.name
296
+
item1._jv.rels.parts.2.name
299
297
300
298
```
301
299
@@ -310,10 +308,10 @@ jm = jsonapiModule(api, config)
310
308
311
309
### Config Options
312
310
313
-
*`jvtag` - The tag in restructured objects to hold object metadata (defaults to `_jv`)
314
-
*`follow_relationships_data` - Whether to follow and expand relationships from the store in the `get` getter (defaults to `true`)
315
-
*`preserve_json` - Whether actions should return the API response json (minus `data`) in `_jv/json` (for access to meta etc) (defaults to `false`)
316
-
*`action_status_clean_age` - What age must action status records be before they are removed (defaults to 600 seconds). Set to `0` to disable.
311
+
-`jvtag` - The tag in restructured objects to hold object metadata (defaults to `_jv`)
312
+
-`followRelationshipsData` - Whether to follow and expand relationships from the store in the `get` getter (defaults to `true`)
313
+
-`preserveJson` - Whether actions should return the API response json (minus `data`) in `_jv/json` (for access to meta etc) (defaults to `false`)
314
+
-`actionStatusCleanAge` - What age must action status records be before they are removed (defaults to 600 seconds). Set to `0` to disable.
317
315
318
316
## Restructured Data
319
317
@@ -412,20 +410,20 @@ There are several scripts set up in `package.json`:
412
410
413
411
`yarn test` - Runs both unit and e2e tests. (Used by `travis`).
414
412
415
-
*Note* - All code is pre-processed with `babel` and `eslint` when testing for backwards compatability and linting.
413
+
_Note_ - All code is pre-processed with `babel` and `eslint` when testing for backwards compatability and linting.
416
414
417
415
### Coding Standards
418
416
419
417
Please follow these guidelines when writing and submitting code:
420
418
421
-
***eslint** - This is run over both the main code and the test suite during tests. See `.eslint.rc.js` for changes to the default rules.
419
+
-**eslint** - This is run over both the main code and the test suite during tests. See `.eslint.rc.js` for changes to the default rules.
422
420
423
-
***>= ES6** - Please try to use ES6 and newer methods (matching the policy that `Vue` has).
421
+
-**>= ES6** - Please try to use ES6 and newer methods (matching the policy that `Vue` has).
424
422
425
-
***Tests** - This project aspires to test-driven development. Please submit unit tests (and ideally e2e tests) with all PRs (unless there's a good reason not to).
423
+
-**Tests** - This project aspires to test-driven development. Please submit unit tests (and ideally e2e tests) with all PRs (unless there's a good reason not to).
426
424
427
-
***Versioning** - Semantic versioning should be used, see https://semver.org for details.
425
+
-**Versioning** - Semantic versioning should be used, see https://semver.org for details.
428
426
429
-
***Continuous Integration** - The project uses [travis(https://travis-ci.com) to run tests against all submissions - PRs that are not passing will not be accepted (without good reason).
427
+
-**Continuous Integration** - The project uses [travis(https://travis-ci.com) to run tests against all submissions - PRs that are not passing will not be accepted (without good reason).
430
428
431
-
***Specific Commits** - Please make all commits/PRs as atomic and specific as possible.
429
+
-**Specific Commits** - Please make all commits/PRs as atomic and specific as possible.
0 commit comments