Skip to content

Instantly share code, notes, and snippets.

@baptistemanson
Last active July 20, 2017 20:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
// 1 - instead of
const state = {
users: [
{ id: 1, name: "Bat", groups: [{ name: "admin" }, { name: "regular" }] },
{ id: 2, name: "Vince", groups: { name: "admin" } },
{ id: 1, name: "Romain", groups: { name: "normal" } }
]
};
// 2- Normalize and index by primary key
const state = {
users: {
1: { id: 1, name: "Bat", groups: [1, 2] },
2: { id: 2, name: "Vince", groups: [1] },
3: { id: 3, name: "Romain", groups: [2] }
},
groups: {
1: { id: 1, name: "admin" },
2: { id: 2, name: "regular" }
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment