Last active
July 20, 2017 20:38
-
-
Save baptistemanson/acf84419d029ba9852c3397ebbc73b05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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