-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathExample2.elm
74 lines (63 loc) · 2.05 KB
/
Example2.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Html exposing (button, text, Html, div, a)
import Html.Events exposing (onClick)
import Html.Attributes exposing (href)
import Task exposing (Task, sleep, andThen)
import Router exposing (Route, match, (:->))
import History exposing (setPath, path, back, forward, length, hash)
import Signal exposing (Mailbox, mailbox, Signal, send, message)
displayBlog _ hash length =
div []
[ button
[ onClick pathChangeMailbox.address (setPath "/contacts.html") ]
[ text "Contacts"]
, button
[ onClick pathChangeMailbox.address back ]
[ text "Back"]
, text "Blog"
, text ("Length : " ++ toString length)
, text ("hash : " ++ toString hash)
]
displayContacts _ hash length =
div []
[ button
[ onClick pathChangeMailbox.address (setPath "/blog.html") ]
[ text "Blog"]
, button
[ onClick pathChangeMailbox.address back ]
[ text "Back"]
, text "Contacts"
, text ("Length : " ++ toString length)
, text ("hash : " ++ toString hash)
]
display404 _ _ _ = text "404"
route : Route (String -> Int -> Html)
route = match
[ "/Example2.elm" :-> app
, "/blog" :-> displayBlog
, "/contacts" :-> displayContacts
] display404
pathChangeMailbox : Mailbox (Task error ())
pathChangeMailbox = mailbox (Task.succeed ())
app _ hash length =
div []
[ button
[ onClick pathChangeMailbox.address (setPath "/blog.html") ]
[ text "Blog"]
, button
[ onClick pathChangeMailbox.address (setPath "/contacts.html") ]
[ text "Contacts"]
, button
[ onClick pathChangeMailbox.address back ]
[ text "Back"]
, button
[ onClick pathChangeMailbox.address forward ]
[ text "Forward"]
, text ("Length : " ++ toString length)
, a [ href "#yo" ] [ text "yo tag" ]
, a [ href "#hello" ] [ text "hello tag" ]
, text ("hash : " ++ toString hash)
]
port runTask : Signal (Task error ())
port runTask =
pathChangeMailbox.signal
main = Signal.map3 route path hash length