Skip to content

Commit 08dcaaa

Browse files
committed
Merge pull request reduxjs#1084 from cyrilf/patch-1
Stay consistent for shouldCallAPI method
2 parents 868aeae + 9401552 commit 08dcaaa

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/recipes/ReducingBoilerplate.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export function loadPosts(userId) {
333333
// Types of actions to emit before and after
334334
types: ['LOAD_POSTS_REQUEST', 'LOAD_POSTS_SUCCESS', 'LOAD_POSTS_FAILURE'],
335335
// Check the cache (optional):
336-
shouldCallAPI: (state) => !state.users[userId],
336+
shouldCallAPI: (state) => !state.posts[userId],
337337
// Perform the fetching:
338338
callAPI: () => fetch(`http://myapi.com/users/${userId}/posts`),
339339
// Arguments to inject in begin/end actions
@@ -403,7 +403,7 @@ After passing it once to [`applyMiddleware(...middlewares)`](../api/applyMiddlew
403403
export function loadPosts(userId) {
404404
return {
405405
types: ['LOAD_POSTS_REQUEST', 'LOAD_POSTS_SUCCESS', 'LOAD_POSTS_FAILURE'],
406-
shouldCallAPI: (state) => !state.users[userId],
406+
shouldCallAPI: (state) => !state.posts[userId],
407407
callAPI: () => fetch(`http://myapi.com/users/${userId}/posts`),
408408
payload: { userId }
409409
}
@@ -412,7 +412,7 @@ export function loadPosts(userId) {
412412
export function loadComments(postId) {
413413
return {
414414
types: ['LOAD_COMMENTS_REQUEST', 'LOAD_COMMENTS_SUCCESS', 'LOAD_COMMENTS_FAILURE'],
415-
shouldCallAPI: (state) => !state.posts[postId],
415+
shouldCallAPI: (state) => !state.comments[postId],
416416
callAPI: () => fetch(`http://myapi.com/posts/${postId}/comments`),
417417
payload: { postId }
418418
}

0 commit comments

Comments
 (0)