/
Types.purs
executable file
·65 lines (50 loc) · 1.75 KB
/
Types.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
-- | Types common to Flame modules
module Flame.Types where
import Prelude
import Effect (Effect)
import Foreign.Object (Object)
import Signal (Signal)
import Web.DOM.Element as WDE
import Web.Event.Event (Event)
-- | Represents a list of events listeners
foreign import data VNodeEvents :: Type
-- | Data (properties, attributes, events) attached to a VNode
-- something missing here is the support for thunks
type VNodeData = {
--snabbdom has both attrs (which use setAttribute) and props; props seem to work for all cases
-- I am not sure whether this distinction will matter
props :: Object String,
on :: VNodeEvents
}
-- | Virtual DOM representation
newtype VNode = VNode
{ sel :: String
, data :: VNodeData
, children :: Array VNode
, elm :: DOMElement
}
-- App abstracts over common fields of an `Application`
type App model message extension = {
view :: model -> Html message,
inputs :: Array (Signal message)
| extension
}
-- | A native HMLT element
type DOMElement = WDE.Element
-- | Type synonym for view functions
type Html = Element
type ToNodeData message = forall b. message -> NodeData b
type Tag = String
-- | Convenience wrapper around `VNode`
data Element message =
Node Tag (Array (NodeData message)) (Array (Element message))
| Text String
derive instance elementFunctor :: Functor Element
-- | Convenience wrapper around `VNodeData`
--snabbom has support for style and class node data but I dont think it is worth it
data NodeData message =
Attribute String String
| Property String Boolean
| Event String message
| RawEvent String (Event -> Effect message)
derive instance nodeDataFunctor :: Functor NodeData