-
Notifications
You must be signed in to change notification settings - Fork 1
perf: Cache posts in redux store or performance #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
src/state/ducks/posts/actions.js
Outdated
| }; | ||
|
|
||
| export { | ||
| // eslint-disable-next-line import/prefer-default-export |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need this line anymore when exporting multiple variables
src/state/ducks/posts/selectors.js
Outdated
|
|
||
| const getHomePosts = state => sortBy => ( | ||
| sort(Object.values(state.posts.home), sortBy) | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simpler way
const getHomePosts = state => sortBy => sort(Object.values(state.posts.home), sortBy);do the same for the others
src/state/ducks/posts/selectors.js
Outdated
| sort(Object.values(state.posts.saved), sortBy) | ||
| ); | ||
|
|
||
| const getSourcePosts = state => (sortBy, source) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the source param is required but the sortBy is optional, so we should put the source to the front
src/state/ducks/posts/selectors.js
Outdated
| ); | ||
|
|
||
| const getSourcePosts = state => (sortBy, source) => ( | ||
| state.posts.sources[source] ? sort(state.posts.sources, sortBy, source) : 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should return an empty array instead of 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and why don't we just pass state.posts.sources[source] instead of sort(state.posts.sources, ... !?
the solution should be sort(state.posts.sources[source] || [], sortBy)
and refactoring the sort function is needed for this change. The sort function is just for sorting an inputted posts array, so only 2 params (posts, sortBy) are required.
src/components/Home/Home.render.js
Outdated
| const title = source ? source.title : 'Explore'; | ||
|
|
||
| return <Home title={title} source={source} {...rest} />; | ||
| return <Home title={title} source={source} {...rest} match={match} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to pass match to Home props anymore because I extracted the source id (source) from it already in
const source = match.params.source ? getSource(match.params.source) : undefined;
return <Home title={title} source={source} {...rest} />;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you just need to change source to sourceId
const sourceId = match.params.sourceId ? getSource(match.params.sourceId) : undefined;
return <Home title={title} sourceId={sourceId} {...rest} />;
No description provided.