-
Notifications
You must be signed in to change notification settings - Fork 6
/
LazyLoading.hs
48 lines (37 loc) · 1.14 KB
/
LazyLoading.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
39
40
41
42
43
44
45
46
47
48
module Example.LazyLoading where
import Data.Text (pack)
import Effectful
import Example.Effects.Debug
import Web.Hyperbole
-- this is already running in a different context
page :: (Hyperbole :> es, Debug :> es) => Page es Contents
page = do
handle content $ do
pure $ do
row (pad 20) $ do
col (gap 10 . border 1 . pad 20) $ do
hyper Contents viewInit
data Contents = Contents
deriving (Show, Read, ViewId)
instance HyperView Contents where
type Action Contents = ContentsAction
data ContentsAction
= Load
| Reload Int
deriving (Show, Read, ViewAction)
content :: (Hyperbole :> es, Debug :> es) => Contents -> ContentsAction -> Eff es (View Contents ())
content _ Load = do
-- Pretend the initial Load takes 1s to complete
delay 1000
pure $ onLoad (Reload 1) 1000 $ do
el id "Loaded, should reload once more..."
content _ (Reload n) = do
-- then reload after a 1s delay (client-side)
pure $ onLoad (Reload (n + 1)) 1000 $ do
col (gap 10) $ do
el_ "Reloaded! polling..."
el_ $ text $ pack $ show n
viewInit :: View Contents ()
viewInit = do
onLoad Load 0 $ do
el id "Lazy Loading..."