Included Resources
Usage
import { resourceReducer } from 'redux-resource';
import { includedResources } from 'redux-resource-plugins';
const authorReducer = resourceReducer('authors', {
plugins: [includedResources]
});
const booksReducer = resourceReducer('books', {
plugins: [includedResources]
});import { actionTypes } from 'redux-resource';
import store from './store';
store.dispatch({
type: actionTypes.READ_RESOURCES_SUCCEEDED,
resourceType: 'authors',
resources: [{
id: 10,
name: 'Sarah'
}],
includedResources: {
// Resources are key'd off by their name.
// The value can be an Object or an Array.
// Here we pass books as an Object. `normalizr` returns
// a shape like this.
books: {
23: {
id: 23,
name: 'Some book'
},
100: {
id: 50,
name: 'Another book'
}
},
// Notice here that comments is an Array. This format works, too.
comments: [
{
id: 23,
name: 'Great author!'
},
{
id: 100,
name: 'One of my favorite authors'
}
]
}
});Related Reading
Last updated