umuro

Elm. App Routes. Example

Oct 19th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Type.Odds10.AppRoute
  2.   exposing
  3.     ( AppRoute(NotInitialized, NotFound, Home,BetSlip,Football)
  4.     , FootballRoute(Search,Match)
  5.     , toRoute
  6.     , toPath
  7.     , doRedirects
  8.     )
  9.  
  10. import RouteParser exposing (..)
  11.  
  12. -- Redirections
  13.  
  14. doRedirects : AppRoute -> AppRoute
  15. doRedirects route =
  16.   case route of
  17.     Home -> Football Search
  18.     _ -> route
  19.  
  20. -- GLobal Routes
  21.  
  22. toRoute location =
  23.   match matchers location
  24.  
  25. type AppRoute
  26.   = NotInitialized
  27.   | NotFound
  28.   | Home
  29.   | BetSlip
  30.   | Football FootballRoute
  31.  
  32. matchers =
  33.   [ static Home ""
  34.   , static Home "/"
  35.   , static BetSlip "/bet_slip"
  36.   , static BetSlip "/bet_slip/"
  37.   ] ++ (mapMatchers Football footballMatchers)
  38.  
  39. toPath : AppRoute -> String
  40. toPath route =
  41.   case route of
  42.     NotInitialized -> "/404"
  43.     NotFound -> "/404"
  44.     Home -> ""
  45.     BetSlip -> "/bet_slip"
  46.     Football football_route -> footballToPath football_route
  47.  
  48. -- Football Routes
  49.  
  50. type FootballRoute
  51.   = Search
  52.   | Match Int
  53.  
  54. footballMatchers =
  55.     [ static Search "/football"
  56.     , static Search "/football/"
  57.     , dyn1 Match "/football/match/" int ""
  58.     ]
  59.  
  60. footballToPath : FootballRoute -> String
  61. footballToPath route =
  62.     case route of
  63.       Search -> "/football"
  64.       Match id -> "/football/match/" ++ (toString id)
Add Comment
Please, Sign In to add comment