The data lives in a single store in Redux and not a multiple store like in Flux. The data is represented by one object tree. This brings about a lot of benefits, such as:
- It is easier to see what your application knows at any given point, so it is easy to serialize or deserialize it.
- It is easier to work with in development, and easier to debug and inspect.
- It easier to do things such as undo/redo if all applied actions produce a new state.
An example of a single store can look like the following:
// principles/store.js
class Store {
getState() {
return {
jedis: [
{ name: "Yoda", id: 1 },
{ name: "Palpatine", id: 2 },
{ name: "Darth Vader", id: 3 }
],
selectedJedi: {
name: "Yoda",
id: 1
}
};
}
}
const store = new Store();
console.log(store.getState());
/*
{
jedis: [
{ name: 'Yoda', id: 1 },
{ name: 'Palpatine', id: 2 },
{ name: 'Darth Vader', id: 3 }
],
selectedJedi: {
name: 'Yoda', id: 1
}
}
*/
As you can see, this is just an object.