mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-03 17:31:58 +03:00
Add example of global state.
This commit is contained in:
parent
40b86aba83
commit
bddcd02141
@ -23,6 +23,7 @@ import Secrets
|
||||
|
||||
type alias Model =
|
||||
{ showMobileMenu : Bool
|
||||
, counter : Int
|
||||
}
|
||||
|
||||
|
||||
@ -45,10 +46,13 @@ type Msg
|
||||
, fragment : Maybe String
|
||||
}
|
||||
| ToggleMobileMenu
|
||||
| Increment
|
||||
|
||||
|
||||
init : a -> Model
|
||||
init maybePagePath =
|
||||
{ showMobileMenu = False
|
||||
, counter = 0
|
||||
}
|
||||
|
||||
|
||||
@ -61,6 +65,9 @@ update msg model =
|
||||
ToggleMobileMenu ->
|
||||
( { model | showMobileMenu = not model.showMobileMenu }, Cmd.none )
|
||||
|
||||
Increment ->
|
||||
( { model | counter = model.counter + 1 }, Cmd.none )
|
||||
|
||||
|
||||
type alias StaticData =
|
||||
Int
|
||||
@ -98,6 +105,7 @@ view stars page model toMsg pageView =
|
||||
else
|
||||
Element.column [ Element.width Element.fill ]
|
||||
[ header stars page.path |> Element.map toMsg
|
||||
, incrementView model |> Element.map toMsg
|
||||
, pageView.body |> Element.map never
|
||||
]
|
||||
)
|
||||
@ -107,12 +115,15 @@ view stars page model toMsg pageView =
|
||||
, Font.family [ Font.typeface "Roboto" ]
|
||||
, Font.color (Element.rgba255 0 0 0 0.8)
|
||||
]
|
||||
|
||||
--|> Html.map liftMsg
|
||||
, title = pageView.title
|
||||
}
|
||||
|
||||
|
||||
incrementView : Model -> Element Msg
|
||||
incrementView model =
|
||||
Element.el [ Element.Events.onClick Increment ] (Element.text <| String.fromInt model.counter)
|
||||
|
||||
|
||||
logoLinkMobile =
|
||||
Element.link []
|
||||
{ url = "/"
|
||||
|
Loading…
Reference in New Issue
Block a user