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