File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -18,14 +18,14 @@ export function invalidateReddit(reddit) {
1818 reddit
1919 }
2020}
21- //开始获取action
21+ //开始获取新闻action
2222function requestPosts ( reddit ) {
2323 return {
2424 type : REQUEST_POSTS ,
2525 reddit
2626 }
2727}
28- //获取成功的action
28+ //获取新闻成功的action
2929function receivePosts ( reddit , json ) {
3030 return {
3131 type : RECEIVE_POSTS ,
@@ -35,7 +35,7 @@ function receivePosts(reddit, json) {
3535 }
3636}
3737
38- //获取文章,先触发开始获取action,完成后触发获取成功的action
38+ //获取文章,先触发requestPosts开始获取action,完成后触发receivePosts获取成功的action
3939function fetchPosts ( reddit ) {
4040 return dispatch => {
4141 dispatch ( requestPosts ( reddit ) )
Original file line number Diff line number Diff line change @@ -11,12 +11,16 @@ class App extends Component {
1111 this . handleRefreshClick = this . handleRefreshClick . bind ( this )
1212 }
1313
14+ //初始化渲染后触发
1415 componentDidMount ( ) {
16+ console . log ( '执行componentDidMount' ) ;
1517 const { dispatch, selectedReddit } = this . props
1618 dispatch ( fetchPostsIfNeeded ( selectedReddit ) )
1719 }
1820
21+ //每次接受新的props触发
1922 componentWillReceiveProps ( nextProps ) {
23+ console . log ( '执行componentWillReceiveProps' , nextProps ) ;
2024 if ( nextProps . selectedReddit !== this . props . selectedReddit ) {
2125 const { dispatch, selectedReddit } = nextProps
2226 dispatch ( fetchPostsIfNeeded ( selectedReddit ) )
You can’t perform that action at this time.
0 commit comments