-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
Main.hs
38 lines (33 loc) · 1.07 KB
/
Main.hs
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
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Common
import Data.Proxy
import Miso
main :: IO ()
main = do
miso $ \currentURI ->
App { initialAction = NoOp
, model = Model currentURI "No event received"
, ..
}
where
update = updateModel
view m = case runRoute (Proxy :: Proxy ClientRoutes) handlers modelUri m of
Left _ -> the404
Right m -> m
events = defaultEvents
subs = [ sseSub "/sse" handleSseMsg
, uriSub HandleURI
]
mountPoint = Nothing
logLevel = Off
handleSseMsg :: SSE String -> Action
handleSseMsg (SSEMessage msg) = ServerMsg msg
handleSseMsg SSEClose = ServerMsg "SSE connection closed"
handleSseMsg SSEError = ServerMsg "SSE error"
updateModel :: Action -> Model -> Effect Action Model
updateModel (ServerMsg msg) m = pure (m {modelMsg = "Event received: " ++ msg})
updateModel (HandleURI u) m = m {modelUri = u} <# pure NoOp
updateModel (ChangeURI u) m = m <# (pushURI u >> pure NoOp)
updateModel NoOp m = noEff m