Members
Methods
(static) apiConfigure(config)
Configure the API -
see https://github.com/mzabriskie/axios#request-config
- Source:
Parameters:
Name | Type | Description |
---|---|---|
config |
Object
|
Axios configuration |
(static) apiCreate(args)
Create a resource via API
- Source:
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object
|
|
Example
import { apiCreate } from 'active-redux';
import Person from '../models/person';
Person.find({ id: '5' });
// => Promise<null>
const person = new Person({ attributes: { name: 'Joe' } });
dispatch(apiCreate({ resource: person })).then((json) => {
// do something with the response json
}).catch((error) => {
// handle error
});
Person.find({ id: '5' });
// => Promise<Person>
(static) apiDelete(args)
Delete a resource via API
- Source:
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object
|
|
Example
import { apiDelete } from 'active-redux';
import Person from '../models/person';
Person.find({ id: '5' });
// => Promise<Person(id='5')>
const person = new Person({ id: '5' });
dispatch(apiDelete({ resource: person })).then((json) => {
// do something with the response json
}).catch((error) => {
// handle error
});
Person.find({ id: '5' });
// => Promise<null>
(static) apiHydrate(data)
Hydrate the store from JSON-API
- Source:
Parameters:
Name | Type | Description |
---|---|---|
data |
Object
|
JSON-API data |
Example
import { apiHydrate } from 'active-redux';
state.api.people
// => {}
const data = [{
type: 'people',
id: '5',
attributes: {
name: 'Joe',
age: 35,
}
}];
dispatch(apiHydrate(data))
state.api.people
// => Object<String: Person>
(static) apiRead(args)
Read a resource via API
- Source:
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object
|
|
Example
import { apiRead } from 'active-redux';
import Person from '../models/person';
Person.all();
// => Promise<[]>
dispatch(apiRead({ resource: Person })).then((json) => {
// do something with the response json
}).catch((error) => {
// handle error
});
Person.all();
// => Promise<Array<Person>>
(static) apiUpdate(args)
Update a resource via API
- Source:
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object
|
|
Example
import { apiUpdate } from 'active-redux';
import Person from '../models/person';
Person.find({ id: '5' });
// => Promise<Person(id='5' name='Joe')>
const person = new Person({ id: '5', attributes: { name: 'Jimmy' } });
dispatch(apiUpdate({ resource: person })).then((json) => {
// do something with the response json
}).catch((error) => {
// handle error
});
Person.find({ id: '5' });
// => Promise<Person(id='5' name='Jimmy')>