Guest User

Untitled

a guest
Dec 15th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. module Main exposing (main)
  2. import Url exposing (Url)
  3. import Html exposing (..)
  4. import Html.Attributes exposing (..)
  5. import Html.Events exposing (..)
  6. import Browser exposing (..)
  7. import Browser.Navigation as Navigation exposing (load)
  8. import Url.Parser exposing (Parser, (</>), int, map, oneOf, s, string)
  9.  
  10. main =
  11. Browser.application
  12. { init = init
  13. , update = update
  14. , subscriptions = subscriptions
  15. , onUrlRequest = StateUrl
  16. , onUrlChange = UrlChange
  17. , view = view -->> toUnstyled
  18. }
  19.  
  20. init : Flags -> Url -> Navigation.Key -> (Model, Cmd Msg)
  21. init flags url key =
  22. Debug.log "Frist Debug Log"
  23. ({query_value = "no val", url = url, fragment = Nothing, query = Nothing, key = key}, Cmd.none)
  24.  
  25.  
  26. type alias Model =
  27. { query_value : String
  28. , url : Url
  29. , fragment : Maybe String
  30. , query : Maybe String
  31. , key : Navigation.Key
  32. }
  33.  
  34. type alias Flags =
  35. {}
  36.  
  37.  
  38. type Msg
  39. = StateUrl UrlRequest
  40. | UrlChange Url
  41. | SomeAction Url
  42.  
  43.  
  44. update : Msg -> Model -> ( Model, Cmd Msg )
  45. update msg model =
  46. case msg of
  47. StateUrl req ->
  48. Debug.log "1"
  49. ( model, Cmd.none )
  50.  
  51. UrlChange url ->
  52. Debug.log "url"
  53. (model, Cmd.none )
  54. SomeAction url ->
  55. (model, Cmd.none)
  56.  
  57.  
  58. subscriptions : Model -> Sub Msg
  59. subscriptions model =
  60. Sub.none
  61.  
  62.  
  63. view model =
  64. { title = "Some Title"
  65. , body = [div [][text "Hello"
  66. , br [][]
  67. , text model.query_value
  68. , br [][]
  69. , text (Maybe.withDefault "no query" model.query)
  70. ]
  71. ,div [][
  72. button [ onClick SomeAction ] [ text "+" ]
  73. ]
  74. ]
  75. }
  76.  
  77.  
  78. -- Route Parsing
  79.  
  80. type Route
  81. = Topic String
  82. | Blog Int
  83. | User String
  84. | Comment String Int
  85.  
  86. routeParser : Parser (Route -> a) a
  87. routeParser =
  88. oneOf
  89. [ map Topic (s "topic" </> string)
  90. , map Blog (s "blog" </> int)
  91. , map User (s "user" </> string)
  92. , map Comment (s "user" </> string </> s "comment" </> int)
  93. ]
Add Comment
Please, Sign In to add comment