How or Can I to use combinedReducer in a reducer?












0















I have a main reducer (byVideoIds), which which generates a dynamic key name based on action.videoId. This object will contact a list of comments. I have normalized the subreducer for comments byIds (object by comment ids), allIds (array of comment ids associated with the video), as well as showing pagination stuff and isFetching.



The issue i am facing and cannot track down, is on comment delete action DELETE_COMMENT_SUCCESS, my state tree is not updated and the array of allIds does not change. As a result my UI is not re-rendered with the changes.



Am i using the combinedREducers correctly here by calling combineReducersComments inside of byVideos reducer. I don't know if the state, action need to be passed here as well on the same line.



With the code below my state tree is loaded correctly and comment data for each video is displayed, however on delete action, the UI is not updated.



If combinedReducers cannot be used this way. What are my options to set the initial state for a [videoId]?



const byVideoIds = (state = {}, action) => {
const { videoId } = action;
switch (action.type) {
case GET_COMMENTS_REQUEST:
return {
...state,
[videoId]: combineReducersComments(state[videoId], action)
};
case GET_COMMENTS_SUCCESS:
return {
...state,
[videoId]: combineReducersComments(state[videoId], action)
};
default:
return state;
}
};

//--------------------------------------------------------
const byIds = (state = {}, action) => {
const { comments } = action;
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return {
...state,
...comments.reduce((obj, comment) => {
obj[comment.id] = comment;
return obj;
}, {})
};
default:
return state;
}
};

const allIds = (state = , action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return action.comments.map(comment => comment.id);
case DELETE_COMMENT_SUCCESS:
return state.filter(id => id !== action.commentId);
default:
return state;
}
};

const page = (state = 1, action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return state + 1;
default:
return state;
}
};

const totalPages = (state = null, action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return action.totalPages;
default:
return state;
}
};

const isFetching = (state = false, action) => {
switch (action.type) {
case GET_COMMENTS_REQUEST:
return true;
case GET_COMMENTS_SUCCESS:
case GET_COMMENTS_FAILURE:
return false;
default:
return state;
}
};


const combineReducersComments = combineReducers({
byIds,
allIds,
page,
totalPages,
isFetching
});









share|improve this question























  • I was able to correct the issue by adding: case DELETE_COMMENT_SUCCESS to videosByIds reducer to update object, which i forgot to do originally.

    – leonard0
    Dec 29 '18 at 22:58


















0















I have a main reducer (byVideoIds), which which generates a dynamic key name based on action.videoId. This object will contact a list of comments. I have normalized the subreducer for comments byIds (object by comment ids), allIds (array of comment ids associated with the video), as well as showing pagination stuff and isFetching.



The issue i am facing and cannot track down, is on comment delete action DELETE_COMMENT_SUCCESS, my state tree is not updated and the array of allIds does not change. As a result my UI is not re-rendered with the changes.



Am i using the combinedREducers correctly here by calling combineReducersComments inside of byVideos reducer. I don't know if the state, action need to be passed here as well on the same line.



With the code below my state tree is loaded correctly and comment data for each video is displayed, however on delete action, the UI is not updated.



If combinedReducers cannot be used this way. What are my options to set the initial state for a [videoId]?



const byVideoIds = (state = {}, action) => {
const { videoId } = action;
switch (action.type) {
case GET_COMMENTS_REQUEST:
return {
...state,
[videoId]: combineReducersComments(state[videoId], action)
};
case GET_COMMENTS_SUCCESS:
return {
...state,
[videoId]: combineReducersComments(state[videoId], action)
};
default:
return state;
}
};

//--------------------------------------------------------
const byIds = (state = {}, action) => {
const { comments } = action;
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return {
...state,
...comments.reduce((obj, comment) => {
obj[comment.id] = comment;
return obj;
}, {})
};
default:
return state;
}
};

const allIds = (state = , action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return action.comments.map(comment => comment.id);
case DELETE_COMMENT_SUCCESS:
return state.filter(id => id !== action.commentId);
default:
return state;
}
};

const page = (state = 1, action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return state + 1;
default:
return state;
}
};

const totalPages = (state = null, action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return action.totalPages;
default:
return state;
}
};

const isFetching = (state = false, action) => {
switch (action.type) {
case GET_COMMENTS_REQUEST:
return true;
case GET_COMMENTS_SUCCESS:
case GET_COMMENTS_FAILURE:
return false;
default:
return state;
}
};


const combineReducersComments = combineReducers({
byIds,
allIds,
page,
totalPages,
isFetching
});









share|improve this question























  • I was able to correct the issue by adding: case DELETE_COMMENT_SUCCESS to videosByIds reducer to update object, which i forgot to do originally.

    – leonard0
    Dec 29 '18 at 22:58
















0












0








0








I have a main reducer (byVideoIds), which which generates a dynamic key name based on action.videoId. This object will contact a list of comments. I have normalized the subreducer for comments byIds (object by comment ids), allIds (array of comment ids associated with the video), as well as showing pagination stuff and isFetching.



The issue i am facing and cannot track down, is on comment delete action DELETE_COMMENT_SUCCESS, my state tree is not updated and the array of allIds does not change. As a result my UI is not re-rendered with the changes.



Am i using the combinedREducers correctly here by calling combineReducersComments inside of byVideos reducer. I don't know if the state, action need to be passed here as well on the same line.



With the code below my state tree is loaded correctly and comment data for each video is displayed, however on delete action, the UI is not updated.



If combinedReducers cannot be used this way. What are my options to set the initial state for a [videoId]?



const byVideoIds = (state = {}, action) => {
const { videoId } = action;
switch (action.type) {
case GET_COMMENTS_REQUEST:
return {
...state,
[videoId]: combineReducersComments(state[videoId], action)
};
case GET_COMMENTS_SUCCESS:
return {
...state,
[videoId]: combineReducersComments(state[videoId], action)
};
default:
return state;
}
};

//--------------------------------------------------------
const byIds = (state = {}, action) => {
const { comments } = action;
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return {
...state,
...comments.reduce((obj, comment) => {
obj[comment.id] = comment;
return obj;
}, {})
};
default:
return state;
}
};

const allIds = (state = , action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return action.comments.map(comment => comment.id);
case DELETE_COMMENT_SUCCESS:
return state.filter(id => id !== action.commentId);
default:
return state;
}
};

const page = (state = 1, action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return state + 1;
default:
return state;
}
};

const totalPages = (state = null, action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return action.totalPages;
default:
return state;
}
};

const isFetching = (state = false, action) => {
switch (action.type) {
case GET_COMMENTS_REQUEST:
return true;
case GET_COMMENTS_SUCCESS:
case GET_COMMENTS_FAILURE:
return false;
default:
return state;
}
};


const combineReducersComments = combineReducers({
byIds,
allIds,
page,
totalPages,
isFetching
});









share|improve this question














I have a main reducer (byVideoIds), which which generates a dynamic key name based on action.videoId. This object will contact a list of comments. I have normalized the subreducer for comments byIds (object by comment ids), allIds (array of comment ids associated with the video), as well as showing pagination stuff and isFetching.



The issue i am facing and cannot track down, is on comment delete action DELETE_COMMENT_SUCCESS, my state tree is not updated and the array of allIds does not change. As a result my UI is not re-rendered with the changes.



Am i using the combinedREducers correctly here by calling combineReducersComments inside of byVideos reducer. I don't know if the state, action need to be passed here as well on the same line.



With the code below my state tree is loaded correctly and comment data for each video is displayed, however on delete action, the UI is not updated.



If combinedReducers cannot be used this way. What are my options to set the initial state for a [videoId]?



const byVideoIds = (state = {}, action) => {
const { videoId } = action;
switch (action.type) {
case GET_COMMENTS_REQUEST:
return {
...state,
[videoId]: combineReducersComments(state[videoId], action)
};
case GET_COMMENTS_SUCCESS:
return {
...state,
[videoId]: combineReducersComments(state[videoId], action)
};
default:
return state;
}
};

//--------------------------------------------------------
const byIds = (state = {}, action) => {
const { comments } = action;
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return {
...state,
...comments.reduce((obj, comment) => {
obj[comment.id] = comment;
return obj;
}, {})
};
default:
return state;
}
};

const allIds = (state = , action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return action.comments.map(comment => comment.id);
case DELETE_COMMENT_SUCCESS:
return state.filter(id => id !== action.commentId);
default:
return state;
}
};

const page = (state = 1, action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return state + 1;
default:
return state;
}
};

const totalPages = (state = null, action) => {
switch (action.type) {
case GET_COMMENTS_SUCCESS:
return action.totalPages;
default:
return state;
}
};

const isFetching = (state = false, action) => {
switch (action.type) {
case GET_COMMENTS_REQUEST:
return true;
case GET_COMMENTS_SUCCESS:
case GET_COMMENTS_FAILURE:
return false;
default:
return state;
}
};


const combineReducersComments = combineReducers({
byIds,
allIds,
page,
totalPages,
isFetching
});






redux react-redux






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 29 '18 at 18:51









leonard0leonard0

1111




1111













  • I was able to correct the issue by adding: case DELETE_COMMENT_SUCCESS to videosByIds reducer to update object, which i forgot to do originally.

    – leonard0
    Dec 29 '18 at 22:58





















  • I was able to correct the issue by adding: case DELETE_COMMENT_SUCCESS to videosByIds reducer to update object, which i forgot to do originally.

    – leonard0
    Dec 29 '18 at 22:58



















I was able to correct the issue by adding: case DELETE_COMMENT_SUCCESS to videosByIds reducer to update object, which i forgot to do originally.

– leonard0
Dec 29 '18 at 22:58







I was able to correct the issue by adding: case DELETE_COMMENT_SUCCESS to videosByIds reducer to update object, which i forgot to do originally.

– leonard0
Dec 29 '18 at 22:58














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53972444%2fhow-or-can-i-to-use-combinedreducer-in-a-reducer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53972444%2fhow-or-can-i-to-use-combinedreducer-in-a-reducer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas