Updates comment-related redux code to support sdk version 0.53.0 #259
1 changed files with 33 additions and 4 deletions
|
@ -5,9 +5,37 @@ const selectState = state => state.comments || {};
|
|||
|
||||
export const selectCommentsById = createSelector(
|
||||
selectState,
|
||||
state => state.byId || {}
|
||||
state => state.commentById || {}
|
||||
);
|
||||
|
||||
export const selectCommentsByClaimId = createSelector(
|
||||
selectState,
|
||||
selectCommentsById,
|
||||
(state, byId) => {
|
||||
const byClaimId = state.byId || {};
|
||||
const comments = {};
|
||||
|
||||
// for every claimId -> commentId, put comments in the object
|
||||
Object.keys(byClaimId).forEach(claimId => {
|
||||
// get all the commentIds that commented on this ClaimId
|
||||
const commentIds = byClaimId[claimId];
|
||||
|
||||
// map a new array of comments by the claimId
|
||||
comments[claimId] = Array(commentIds === null ? 0 : commentIds.length);
|
||||
for (let i = 0; i < commentIds.length; i++) {
|
||||
comments[claimId][i] = byId[commentIds[i]];
|
||||
}
|
||||
});
|
||||
|
||||
return comments;
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
// previously this used a mapping from claimId -> Array<Comments>
|
||||
/* export const selectCommentsById = createSelector(
|
||||
selectState,
|
||||
state => state.byId || {}
|
||||
); */
|
||||
export const selectCommentsByUri = createSelector(
|
||||
selectState,
|
||||
state => {
|
||||
|
@ -21,16 +49,17 @@ export const selectCommentsByUri = createSelector(
|
|||
comments[uri] = claimId;
|
||||
}
|
||||
});
|
||||
|
||||
return comments;
|
||||
}
|
||||
);
|
||||
|
||||
export const makeSelectCommentsForUri = (uri: string) =>
|
||||
createSelector(
|
||||
selectCommentsById,
|
||||
selectCommentsByClaimId,
|
||||
selectCommentsByUri,
|
||||
(byId, byUri) => {
|
||||
(byClaimId, byUri) => {
|
||||
const claimId = byUri[uri];
|
||||
return byId && byId[claimId];
|
||||
return byClaimId && byClaimId[claimId];
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue
Why do we need this new selector? (Not saying we don't, I'm just trying to understand the logic)
Is it that in you first get a list of the children comment ids, then for each child, get the actual comment?
It also helps to explain why you are doing something in a comment instead of what the code is doing, since that can usually be figured out.
ex: "map a new array of comments by the claimId"
I can see that's what this code is doing, but I don't know why it's doing that.