Redux todoapp using normalizr(https://github.com/gaearon/normalizr).
npm install
npm start
{
"todos":[
{
"todo":{
"id":1,
"body":"ticket #1",
"status":1,
"userId": 1,
"user":{
"id":1,
"name":"john"
}
}
}
]
}
{
"users":[
{
"user":{
"id":1,
"name":"john",
"status":1
}
}
]
}
/todos.json
has a nested object which represents a assigned user itself.
Convert /todos.json
to the flat structure which consists of result
and entities
.
{
result: [{todo: "todo:1"}],
entities: {
todos: {
"todo:1": {
"id": 1,
"body":"ticket #1",
"status":1,
"userId": 1,
"user":"user:1"
}
},
users: {
"user:1": {
id: 1,
name: 'john'
}
}
}
}
Entities represent data itself, like a database record.
Result represents api result, but it has the entity id only.
Insert, update, delete entities.
Other reducers handles results. In most cases, it updates a list of entity ids, for example, appends(prepends) a new entity, remove a deleted entity.
Container receives a entity id or a list of entity ids as props and get entities from Provider
provided by redux-connect
(https://github.com/reactjs/react-redux).