-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.fm
More file actions
53 lines (46 loc) · 941 Bytes
/
App.fm
File metadata and controls
53 lines (46 loc) · 941 Bytes
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
import Nat
import Pair
import String
import Unit
Prop : Type
Pair(String, String)
// Doc is a renderable document
T Doc
| txt(value : String)
| num(value : Number)
| img(
size : Pair(Number, Number),
data : Pair(Number, Number) -> Number)
| box(
tag : String,
props : List(Prop),
children : List(Doc))
// An event
T Event
| mouseclick(x : Number, y : Number)
| mousemove(x : Number, y : Number)
| keypress(key : Number)
| keydown(key : Number)
| keyup(key : Number)
// App is an interactive application
T App{A}
| app(
state : A,
render : (state : A) -> Doc,
update : (event : Event, state : A) -> A
)
// Gets the state
get_state(A; app : App(A)) : A
case app
| app => app.state
: A
// Renders the state
get_render(A; app : App(A)) : A -> Doc
case app
| app => app.render
: A -> Doc
// Updates the state
get_update(A; app : App(A)) : Event -> A -> A
case app
| app => app.update
: Event -> A -> A