-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.purs
72 lines (61 loc) · 1.69 KB
/
UI.purs
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
module MVC.Record.UI
( UIRecordProps
, class UIRecord
, uiRecord
) where
import MVC.Record (class UpdateRecord, class ViewRecord, ViewResult, updateRecord, viewRecord)
import MVC.Record.Init (class InitRecord, initRecord)
import MVC.Record.Types (RecordMsg, RecordState)
import MVC.Types (UI)
import MVC.Util (class MapProp, mapProp)
import Type.Proxy (Proxy(..))
type UIRecordProps :: (Type -> Type) -> Type -> Type -> Type
type UIRecordProps srf msg sta =
{ viewEntries :: Array (ViewResult srf msg) -> srf msg
}
class
UIRecord
(uis :: Row Type)
(srf :: Type -> Type)
(rmsg :: Row Type)
(rsta :: Row Type)
| uis -> srf rmsg rsta
where
uiRecord
:: Record uis
-> UIRecordProps srf (RecordMsg rmsg) (RecordState rsta)
-> UI srf (RecordMsg rmsg) (RecordState rsta)
instance
( MapProp "init" uis inits
, MapProp "update" uis updates
, MapProp "view" uis views
, InitRecord inits rsta
, UpdateRecord updates rmsg rsta
, ViewRecord srf views rmsg rsta
) =>
UIRecord uis srf rmsg rsta
where
uiRecord
:: Record uis
-> UIRecordProps srf (RecordMsg rmsg) (RecordState rsta)
-> UI srf (RecordMsg rmsg) (RecordState rsta)
uiRecord uis props =
{ init: initRecord inits
, update: updateRecord updates
, view: viewRecord views { viewEntries: props.viewEntries }
}
where
--- Records
inits :: Record inits
inits = mapProp prxInit uis
updates :: Record updates
updates = mapProp prxUpdate uis
views :: Record views
views = mapProp prxView uis
-- Proxies
prxInit :: Proxy "init"
prxInit = Proxy
prxUpdate :: Proxy "update"
prxUpdate = Proxy
prxView :: Proxy "view"
prxView = Proxy