@@ -4,28 +4,28 @@ export const REQUEST_POSTS = 'REQUEST_POSTS'
44export const RECEIVE_POSTS = 'RECEIVE_POSTS'
55export const SELECT_REDDIT = 'SELECT_REDDIT'
66export const INVALIDATE_REDDIT = 'INVALIDATE_REDDIT'
7-
7+ //选择新闻类型action
88export function selectReddit ( reddit ) {
99 return {
1010 type : SELECT_REDDIT ,
1111 reddit
1212 }
1313}
14-
14+ //废弃新闻类型action
1515export function invalidateReddit ( reddit ) {
1616 return {
1717 type : INVALIDATE_REDDIT ,
1818 reddit
1919 }
2020}
21-
21+ //开始获取action
2222function requestPosts ( reddit ) {
2323 return {
2424 type : REQUEST_POSTS ,
2525 reddit
2626 }
2727}
28-
28+ //获取成功的action
2929function receivePosts ( reddit , json ) {
3030 return {
3131 type : RECEIVE_POSTS ,
@@ -35,6 +35,7 @@ function receivePosts(reddit, json) {
3535 }
3636}
3737
38+ //获取文章,先触发开始获取action,完成后触发获取成功的action
3839function fetchPosts ( reddit ) {
3940 return dispatch => {
4041 dispatch ( requestPosts ( reddit ) )
@@ -44,6 +45,7 @@ function fetchPosts(reddit) {
4445 }
4546}
4647
48+ //是否需要获取文章
4749function shouldFetchPosts ( state , reddit ) {
4850 const posts = state . postsByReddit [ reddit ]
4951 if ( ! posts ) {
@@ -55,6 +57,7 @@ function shouldFetchPosts(state, reddit) {
5557 return posts . didInvalidate
5658}
5759
60+ //如果需要则开始获取文章
5861export function fetchPostsIfNeeded ( reddit ) {
5962 return ( dispatch , getState ) => {
6063 if ( shouldFetchPosts ( getState ( ) , reddit ) ) {
0 commit comments