File tree Expand file tree Collapse file tree 5 files changed +31
-5
lines changed Expand file tree Collapse file tree 5 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ An extensible virtual-dom library for PureScript.
4
4
5
5
## Overview
6
6
7
- ` Halogen.VDom ` is a "batteries not included" virtual-dom library for PureScript
8
- with inspiration drawn from:
7
+ ` Halogen.VDom ` is a bare-bones virtual-dom library for PureScript with
8
+ inspiration drawn from:
9
9
10
10
* https://github.com/Matt-Esch/virtual-dom
11
11
* https://github.com/paldepind/snabbdom
@@ -17,9 +17,10 @@ It's goals being:
17
17
2 . To be as fast as possible given (1).
18
18
3 . To be extensible.
19
19
20
- Notably, ` Halogen.VDom ` is largely useless out of the box. It does not support
21
- attributes, properties, or event listeners. It is intended to be extended
22
- (and likely ` newtype ` d) by other frameworks to suit their needs.
20
+ Notably, ` Halogen.VDom ` is largely useless out of the box. You'll need to bring
21
+ your own attributes, properties, and event listeners (though there is a working
22
+ implementation included). It is intended to be extended (and likely
23
+ ` newtype ` d) by other frameworks to suit their needs.
23
24
24
25
---
25
26
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ type VDomMachine eff a b = Machine (Eff eff) a b
30
30
31
31
type VDomStep eff a b = Eff eff (Step (Eff eff ) a b )
32
32
33
+ -- | Widget machines recursively reference the configured spec to potentially
34
+ -- | enable recursive trees of Widgets.
33
35
newtype VDomSpec eff a w = VDomSpec
34
36
{ buildWidget ∷ VDomSpec eff a w → VDomMachine eff w DOM.Node
35
37
, buildAttributes ∷ DOM.Element → VDomMachine eff a Unit
@@ -38,6 +40,15 @@ newtype VDomSpec eff a w = VDomSpec
38
40
39
41
type VDomEffects eff = (dom ∷ DOM | eff )
40
42
43
+ -- | Starts an initial `VDom` machine by providing a `VDomSpec`.
44
+ -- |
45
+ -- | ```purescript
46
+ -- | main = do
47
+ -- | machine1 ← buildVDom spec vdomTree1
48
+ -- | machine2 ← Machine.step machine1 vdomTree2
49
+ -- | machine3 ← Machine.step machine2 vdomTree3
50
+ -- | ...
51
+ -- | ````
41
52
buildVDom
42
53
∷ ∀ eff a w
43
54
. VDomSpec (VDomEffects eff ) a w
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ import Halogen.VDom.Types (Namespace(..))
27
27
import Halogen.VDom.Util as Util
28
28
import Unsafe.Coerce (unsafeCoerce )
29
29
30
+ -- | Attributes, properties, event handlers, and element lifecycles.
31
+ -- | Parameterized by the type of handlers outputs.
30
32
data Prop a
31
33
= Attribute (Maybe Namespace ) String String
32
34
| Property String PropValue
@@ -60,6 +62,9 @@ propFromInt = unsafeCoerce
60
62
propFromNumber ∷ Number → PropValue
61
63
propFromNumber = unsafeCoerce
62
64
65
+ -- | A `Machine`` for applying attributes, properties, and event handlers.
66
+ -- | An emitter effect must be provided to respond to events. For example,
67
+ -- | to allow arbitrary effects in event handlers, one could use `id`.
63
68
buildProp
64
69
∷ ∀ eff a
65
70
. (a → Eff (ref ∷ REF , dom ∷ DOM | eff ) Unit )
Original file line number Diff line number Diff line change @@ -21,12 +21,15 @@ data Step m a b = Step b (Machine m a b) (m Unit)
21
21
instance functorStep ∷ Functor m ⇒ Functor (Step m a ) where
22
22
map f (Step x m d) = Step (f x) (m >>> map (map f)) d
23
23
24
+ -- | Returns the output value of a `Step`.
24
25
extract ∷ ∀ m a b . Step m a b → b
25
26
extract (Step x _ _) = x
26
27
28
+ -- | Runs the next step.
27
29
step ∷ ∀ m a b . Step m a b → a → m (Step m a b )
28
30
step (Step _ m _) = m
29
31
32
+ -- | Runs the finalizer associated with a `Step`
30
33
halt ∷ ∀ m a b . Step m a b → m Unit
31
34
halt (Step _ _ h) = h
32
35
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ import Data.Newtype (class Newtype)
18
18
import Data.Tuple (Tuple )
19
19
import Unsafe.Coerce (unsafeCoerce )
20
20
21
+ -- | The core virtual-dom tree type, where `a` is the type of attributes,
22
+ -- | and `w` is the type of "widgets". Widgets are machines that have complete
23
+ -- | control over the lifecycle of some `DOM.Node`.
24
+ -- |
25
+ -- | The `Grafted` constructor and associated machinery enables `bimap`
26
+ -- | fusion using a Coyoneda-like encoding.
21
27
data VDom a w
22
28
= Text String
23
29
| Elem (ElemSpec a ) (Array (VDom a w ))
You can’t perform that action at this time.
0 commit comments