Let's say my state looks something like this (taken from https://redux.js.org/usage/structuring-reducers/normalizing-state-shape):
{
posts : {
byId : {
"post1" : {
id : "post1",
author : "user1",
body : "......",
comments : ["comment1", "comment2"]
},
"post2" : {
id : "post2",
author : "user2",
body : "......",
comments : ["comment3", "comment4", "comment5"]
}
},
allIds : ["post1", "post2"]
},
comments : {
byId : {
"comment1" : {
id : "comment1",
author : "user1",
comment : ".....",
},
"comment2" : {
id : "comment2",
author : "user2",
comment : ".....",
}
},
allIds : ["comment1", "comment2"]
},
users : {
byId : {
"user1" : {
username : "user1",
name : "User 1",
},
"user2" : {
username : "user2",
name : "User 2",
}
},
allIds : ["user1", "user2"]
}
}
And accordingly I've created 3 slices using Redux-Toolkit's createSlice: postsSlice, commentsSlice, usersSlice.
This is simple enough.
But now I want to add another layer to the state to keep track of blogs, and so the whole structure above needs to be nested and repeated for each blog:
{
blogs: {
byId: {
"blog1": {
posts: {...},
comments: {...},
users: {...}
},
"blog2": {
posts: {...},
comments: {...},
users: {...}
},
},
allIds: ["blog1", "blog2"]
}
}
Now I need to use createSlice to create a new slice, blogsSlice. But for each blog item in this slice I need a sub-state that is comprised of the other 3 slices.
How do I combine the slices/reducers in a way that will actually create this structure? How should I define the initial state and reducer functions that I pass to createSlice in order to make this structure work?