Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import { Middleware, MiddlewareAPI, Dispatch, Action } from "redux"
  2.  
  3. export const logger: Middleware = <S>(api: MiddlewareAPI<S>) => (
  4. next: Dispatch<S>
  5. ) => <A extends Action>(action: A): A => {
  6. console.log("Before")
  7. const result = next(action)
  8. if (action.type.HTTPStatus) {
  9. console.log("HERE IS AN ERROR")
  10. }
  11.  
  12. console.log("After", api.getState())
  13. return result
  14. }
  15.  
  16. export const getTelevisionChannels = (televisionIds: string[]) => async (
  17. dispatch: Dispatch<AppState>
  18. ) => {
  19. try {
  20. const response = await API.post(
  21. "/Channels/querys/status",
  22. { body: JSON.stringify({ televisionIds }) },
  23. true,
  24. dispatch
  25. )
  26. const televisionChannels = await response.json()
  27. televisionChannels.map((televisionChannel: any) =>
  28. dispatch(
  29. getChannelsSuccess(televisionChannel.televisionId, televisionChannel.channels)
  30. )
  31. )
  32. } catch (err) {
  33. dispatch(push("/404"))
  34. console.log(err)
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement