Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. const memory = {}
  2.  
  3. const isLoading = (state = false, action = {}, mem = memory) => {
  4. switch (action.type) {
  5. case 'LIST':
  6. return !mem[action.payload.category]
  7. case 'VIDEO':
  8. return !mem[action.payload.slug]
  9. case 'VIDEOS_FETCHED':
  10. return !(mem[action.payload.category] = true)
  11. case 'VIDEO_FOUND':
  12. return !(mem[action.payload.slug] = true)
  13. default:
  14. return state
  15. }
  16. }
  17.  
  18.  
  19.  
  20. // the thunk for /video/:slug has to change to this:
  21.  
  22. VIDEO: {
  23. path: '/video/:slug',
  24. thunk: async (dispatch, getState) => {
  25. const { location: { payload: { slug } } } = getState()
  26. const video = await fetchData(`/api/video/${slug}`)
  27.  
  28. if (!video) {
  29. return dispatch({ type: NOT_FOUND })
  30. }
  31.  
  32. dispatch({ type: 'VIDEO_FOUND', payload: { slug, video }) // put the slug in the payload now
  33. }
  34. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement