Updates comment-related redux code to support sdk version 0.53.0 #259

Merged
osilkin98 merged 18 commits from sdk-update into master 2020-01-23 21:50:02 +01:00
Showing only changes of commit 1038ff16c8 - Show all commits

View file

@ -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;
}
neb-b commented 2020-01-16 17:23:06 +01:00 (Migrated from github.com)
Review

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.

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.
);
// 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];
}
);