Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const memory = {}
- const isLoading = (state = false, action = {}, mem = memory) => {
- switch (action.type) {
- case 'LIST':
- return !mem[action.payload.category]
- case 'VIDEO':
- return !mem[action.payload.slug]
- case 'VIDEOS_FETCHED':
- return !(mem[action.payload.category] = true)
- case 'VIDEO_FOUND':
- return !(mem[action.payload.slug] = true)
- default:
- return state
- }
- }
- // the thunk for /video/:slug has to change to this:
- VIDEO: {
- path: '/video/:slug',
- thunk: async (dispatch, getState) => {
- const { location: { payload: { slug } } } = getState()
- const video = await fetchData(`/api/video/${slug}`)
- if (!video) {
- return dispatch({ type: NOT_FOUND })
- }
- dispatch({ type: 'VIDEO_FOUND', payload: { slug, video }) // put the slug in the payload now
- }
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement