Last active
December 2, 2016 12:41
-
-
Save nojaf/f7a303ded62dcd0c12009953dc60f1bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Dict exposing (Dict) | |
type Page | |
= NotFound | |
| LeaderBoardPage | |
| LoginPage | |
| RunnerPage | |
routes : Dict String Page | |
routes = | |
Dict.fromList [("#/", LeaderBoardPage) | |
,("", LeaderBoardPage) | |
,("#/login", LoginPage) | |
,("#/runner", RunnerPage) | |
,("#notfound", NotFound)] | |
hashToPage : String -> Page | |
hashToPage hash = | |
Dict.get hash routes | |
|> Maybe.withDefault NotFound | |
pageToHash : Page -> String | |
pageToHash page = | |
Dict.toList routes | |
|> List.filter (\(hash, p) -> p == page) | |
|> List.head | |
|> Maybe.withDefault ("#notfound", NotFound) | |
|> Tuple.first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment