-
Notifications
You must be signed in to change notification settings - Fork 22
/
Helper.elm
48 lines (32 loc) · 981 Bytes
/
Helper.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Helper exposing (Model, Msg(..), init, update, view)
{- This module has functions for showing and hiding the text -}
import Html exposing (Html, div, text)
type alias Model =
{ text : String
, visible : Bool
}
init : String -> ( Model, Cmd Msg )
init text =
{- Returning Cmd Msg from child module is not necessary,
and the signature of init and update function might be simplified to:
String -> Model
Msg -> Model -> Model
Here I return Cmd.none just to follow Fractal Architecture pattern.
-}
( Model text False, Cmd.none )
type Msg
= Show
| Hide
view : Model -> Html Msg
view model =
if model.visible == True then
div [] [ text model.text ]
else
text ""
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Show ->
( { model | visible = True }, Cmd.none )
Hide ->
( { model | visible = False }, Cmd.none )