attamodel
v1.2.2
Published
An ORM-like class for managing your Redux State in a simple immutable way.
Downloads
11
Keywords
Readme
Attamodel
An ORM-like class for managing your Redux State in a simple immutable way
Install
npm install --save attamodel
API Docs Site
Usage
import {AttaModel} from 'attamodel'
// action = {
// data: [
// {id: '12345', name: 'My Blog Post 1'},
// {id: '56789', name: 'My Blog Post 2'},
// {id: '101112', name: 'My Blog Post 3'}
// ],
// meta: {
// page: 1,
// page_size: 50,
// total_pages: 1,
// total_results: 3
// },
// params: {}
// }
// someReducer.js
// state = {}
case GET_POSTS_SUCCESS:
const data = new AttaModel(state, 'posts')
return {
...data
.bulkInsert(action.data)
.addParams(action.params),
.addMeta(action.meta)
.getNextState(),
error: false
}
// nextState = {
// posts: {
// '12345': {id: '12345', name: 'My Blog Post 1'},
// '56789': {id: '56789', name: 'My Blog Post 2'},
// '101112': {id: '101112', name: 'My Blog Post 3'}
// },
// ids: {
// '12345': '12345',
// '56789': '56789',
// '101112': '101112'
// },
// meta: {
// page: 1,
// page_size: 50,
// total_pages: 1,
// total_results: 3
// },
// params: {
// }
// }
License
Apache-2.0 © Attainia