@@ -62,7 +62,7 @@ export const SELECT_SUBREDDIT = 'SELECT_SUBREDDIT'
6262export function selectSubreddit (subreddit ) {
6363 return {
6464 type: SELECT_SUBREDDIT ,
65- subreddit
65+ subreddit,
6666 }
6767}
6868```
@@ -75,7 +75,7 @@ export const INVALIDATE_SUBREDDIT = 'INVALIDATE_SUBREDDIT'
7575export function invalidateSubreddit (subreddit ) {
7676 return {
7777 type: INVALIDATE_SUBREDDIT ,
78- subreddit
78+ subreddit,
7979 }
8080}
8181```
@@ -90,7 +90,7 @@ export const REQUEST_POSTS = 'REQUEST_POSTS'
9090function requestPosts (subreddit ) {
9191 return {
9292 type: REQUEST_POSTS ,
93- subreddit
93+ subreddit,
9494 }
9595}
9696```
@@ -106,8 +106,8 @@ function receivePosts(subreddit, json) {
106106 return {
107107 type: RECEIVE_POSTS ,
108108 subreddit,
109- posts: json .data .children .map (child => child .data ),
110- receivedAt: Date .now ()
109+ posts: json .data .children .map (( child ) => child .data ),
110+ receivedAt: Date .now (),
111111 }
112112}
113113```
@@ -225,7 +225,7 @@ import {
225225 SELECT_SUBREDDIT ,
226226 INVALIDATE_SUBREDDIT ,
227227 REQUEST_POSTS ,
228- RECEIVE_POSTS
228+ RECEIVE_POSTS ,
229229} from ' ../actions'
230230
231231function selectedSubreddit (state = ' reactjs' , action ) {
@@ -241,26 +241,26 @@ function posts(
241241 state = {
242242 isFetching: false ,
243243 didInvalidate: false ,
244- items: []
244+ items: [],
245245 },
246246 action
247247) {
248248 switch (action .type ) {
249249 case INVALIDATE_SUBREDDIT :
250250 return Object .assign ({}, state, {
251- didInvalidate: true
251+ didInvalidate: true ,
252252 })
253253 case REQUEST_POSTS :
254254 return Object .assign ({}, state, {
255255 isFetching: true ,
256- didInvalidate: false
256+ didInvalidate: false ,
257257 })
258258 case RECEIVE_POSTS :
259259 return Object .assign ({}, state, {
260260 isFetching: false ,
261261 didInvalidate: false ,
262262 items: action .posts ,
263- lastUpdated: action .receivedAt
263+ lastUpdated: action .receivedAt ,
264264 })
265265 default :
266266 return state
@@ -273,7 +273,7 @@ function postsBySubreddit(state = {}, action) {
273273 case RECEIVE_POSTS :
274274 case REQUEST_POSTS :
275275 return Object .assign ({}, state, {
276- [action .subreddit ]: posts (state[action .subreddit ], action)
276+ [action .subreddit ]: posts (state[action .subreddit ], action),
277277 })
278278 default :
279279 return state
@@ -282,7 +282,7 @@ function postsBySubreddit(state = {}, action) {
282282
283283const rootReducer = combineReducers ({
284284 postsBySubreddit,
285- selectedSubreddit
285+ selectedSubreddit,
286286})
287287
288288export default rootReducer
@@ -294,7 +294,7 @@ In this code, there are two interesting parts:
294294
295295 ``` js
296296 return Object .assign ({}, state, {
297- [action .subreddit ]: posts (state[action .subreddit ], action)
297+ [action .subreddit ]: posts (state[action .subreddit ], action),
298298 })
299299 ```
300300
@@ -327,7 +327,7 @@ export const REQUEST_POSTS = 'REQUEST_POSTS'
327327function requestPosts (subreddit ) {
328328 return {
329329 type: REQUEST_POSTS ,
330- subreddit
330+ subreddit,
331331 }
332332}
333333
@@ -336,16 +336,16 @@ function receivePosts(subreddit, json) {
336336 return {
337337 type: RECEIVE_POSTS ,
338338 subreddit,
339- posts: json .data .children .map (child => child .data ),
340- receivedAt: Date .now ()
339+ posts: json .data .children .map (( child ) => child .data ),
340+ receivedAt: Date .now (),
341341 }
342342}
343343
344344export const INVALIDATE_SUBREDDIT = ' INVALIDATE_SUBREDDIT'
345345export function invalidateSubreddit (subreddit ) {
346346 return {
347347 type: INVALIDATE_SUBREDDIT ,
348- subreddit
348+ subreddit,
349349 }
350350}
351351
@@ -358,7 +358,7 @@ export function fetchPosts(subreddit) {
358358 // It passes the dispatch method as an argument to the function,
359359 // thus making it able to dispatch actions itself.
360360
361- return function (dispatch ) {
361+ return function (dispatch ) {
362362 // First dispatch: the app state is updated to inform
363363 // that the API call is starting.
364364
@@ -372,14 +372,14 @@ export function fetchPosts(subreddit) {
372372
373373 return fetch (` https://www.reddit.com/r/${ subreddit} .json` )
374374 .then (
375- response => response .json (),
375+ ( response ) => response .json (),
376376 // Do not use catch, because that will also catch
377377 // any errors in the dispatch and resulting render,
378378 // causing a loop of 'Unexpected batch number' errors.
379379 // https://github.com/facebook/react/issues/6895
380- error => console .log (' An error occurred.' , error)
380+ ( error ) => console .log (' An error occurred.' , error)
381381 )
382- .then (json =>
382+ .then (( json ) =>
383383 // We can dispatch many times!
384384 // Here, we update the app state with the results of the API call.
385385
@@ -443,7 +443,7 @@ export const REQUEST_POSTS = 'REQUEST_POSTS'
443443function requestPosts (subreddit ) {
444444 return {
445445 type: REQUEST_POSTS ,
446- subreddit
446+ subreddit,
447447 }
448448}
449449
@@ -452,25 +452,25 @@ function receivePosts(subreddit, json) {
452452 return {
453453 type: RECEIVE_POSTS ,
454454 subreddit,
455- posts: json .data .children .map (child => child .data ),
456- receivedAt: Date .now ()
455+ posts: json .data .children .map (( child ) => child .data ),
456+ receivedAt: Date .now (),
457457 }
458458}
459459
460460export const INVALIDATE_SUBREDDIT = ' INVALIDATE_SUBREDDIT'
461461export function invalidateSubreddit (subreddit ) {
462462 return {
463463 type: INVALIDATE_SUBREDDIT ,
464- subreddit
464+ subreddit,
465465 }
466466}
467467
468468function fetchPosts (subreddit ) {
469- return dispatch => {
469+ return ( dispatch ) => {
470470 dispatch (requestPosts (subreddit))
471471 return fetch (` https://www.reddit.com/r/${ subreddit} .json` )
472- .then (response => response .json ())
473- .then (json => dispatch (receivePosts (subreddit, json)))
472+ .then (( response ) => response .json ())
473+ .then (( json ) => dispatch (receivePosts (subreddit, json)))
474474 }
475475}
476476
0 commit comments