I'm trying to grok Redux's async Reddit API example code
But I'm having a really hard time understanding what's going on with these two functions:
//action
function shouldFetchPosts(state, subreddit) {
const posts = state.postsBySubreddit[subreddit]
if (!posts) {
return true
} else if (posts.isFetching) {
return false
} else {
return posts.didInvalidate
}
}
//reducer
function postsBySubreddit(state = {}, action) {
switch (action.type) {
case INVALIDATE_SUBREDDIT:
case RECEIVE_POSTS:
case REQUEST_POSTS:
return Object.assign({}, state, {
[action.subreddit]: posts(state[action.subreddit], action)
})
default:
return state
}
}
In particuar, postsbySubreddit[subreddit]; I've never seen a function accessed with subscript notation, and doesn't that function require a parameter when it's called?