https://github.com/uptick/redux-jam
A Redux JSON API model layer.
https://github.com/uptick/redux-jam
Last synced: about 1 year ago
JSON representation
A Redux JSON API model layer.
- Host: GitHub
- URL: https://github.com/uptick/redux-jam
- Owner: uptick
- License: gpl-3.0
- Created: 2016-12-18T08:02:21.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-23T04:07:36.000Z (about 8 years ago)
- Last Synced: 2025-02-25T21:38:14.176Z (over 1 year ago)
- Language: JavaScript
- Size: 717 KB
- Stars: 0
- Watchers: 13
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-jam
[](http://badge.fury.io/js/redux-jam)

`redux-jam` aims to make interacting with relational database based APIs
easier and more powerful.
## Installation
```bash
npm install redux-jam
```
or
```bash
yarn add redux-jam
```
Add the JAM model reducer to your root reducer:
```js
import {reducer as model} from 'redux-jam'
const rootReducer = combineReducers({
model,
...
})
export default rootReducer
```
## Defining a Schema
Before data can be manipulated a schema describing the structure of the data
must be defined. There are a number of ways to do it, the two most common are
to define the data manually, or import it automatically using an external
package.
### Manual Definition
Schemas are built using the `Schema` class:
```js
import {Schema} from 'redux-jam'
let schema = new Schema()
```
To define models in a schema, use the `merge` method, which accepts an object
argument describing a part of a schema:
```python
schema.merge({})
```
`merge` may be called any number of times. Each subsequent call will overwrite
any overlapping models.
The structure of the schema object is similar in some ways to the structure of
a JSON-API object. Take for example the following definition of a movie:
```js
{
movie: {
attributes: {
name: {
required: true
},
duration: {}
},
relationships: {
actors: {
type: "person",
many: true,
relatedName: "acted_in"
}
}
api: {
list: () => {},
detail: () => {},
create: () => {},
update: () => {},
delete: () => {}
}
},
person: {
attributes: {
name: {
required: true
}
},
api: {
list: () => {},
detail: () => {},
create: () => {},
update: () => {},
delete: () => {}
}
}
}
```
This defines two models: `movie` and `person`. The `api` sections of each
model are placeholders for calls to API endpoints. They should return promises,
which in turn return JSON-API structured data.
Options for attributes are currently limited to `required`.
Options for relationships:
* type
* required
* many
* relatedName
### Django + DRF
If you're using Django and DRF, your schema can be loaded into JAM
automatically, which is particularly convenient.
Refer to [Django-JAM](https://github.com/uptick/django-jam)
## Loading Data
## Transactions