Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

Commit

Permalink
Update Main.elm to use Navigation package
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Rijnders committed Mar 7, 2018
1 parent 108777a commit d1d1814
Showing 1 changed file with 74 additions and 3 deletions.
77 changes: 74 additions & 3 deletions src/Main.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,79 @@
module Main exposing (main)

import Html exposing (Html)
import Html exposing (..)
import Html.Attributes exposing (..)
import Navigation


main : Html msg
main =
Html.text "Aloha"
Navigation.program UrlChange
{ init = init
, view = view
, update = update
, subscriptions = \_ -> Sub.none
}



-- MODEL


type alias Model =
{ history : List Navigation.Location
}


init : Navigation.Location -> ( Model, Cmd Msg )
init location =
( Model [ location ]
, Cmd.none
)



-- UPDATE


type Msg
= UrlChange Navigation.Location



{- We are just storing the location in our history in this example, but
normally, you would use a package like evancz/url-parser to parse the path
or hash into nicely structured Elm values.
<http://package.elm-lang.org/packages/evancz/url-parser/latest>
-}


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
UrlChange location ->
( { model | history = location :: model.history }
, Cmd.none
)



-- VIEW


view : Model -> Html msg
view model =
div []
[ h1 [] [ text "Pages" ]
, ul [] (List.map viewLink [ "bears", "cats", "dogs", "elephants", "fish" ])
, h1 [] [ text "History" ]
, ul [] (List.map viewLocation model.history)
]


viewLink : String -> Html msg
viewLink name =
li [] [ a [ href ("#" ++ name) ] [ text name ] ]


viewLocation : Navigation.Location -> Html msg
viewLocation location =
li [] [ text (location.pathname ++ location.hash) ]

0 comments on commit d1d1814

Please sign in to comment.