Skip to content

Commit fb18a6e

Browse files
authored
Add some comments. Update README. (#8)
1 parent e2ab059 commit fb18a6e

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ An extensible virtual-dom library for PureScript.
44

55
## Overview
66

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:
99

1010
* https://github.com/Matt-Esch/virtual-dom
1111
* https://github.com/paldepind/snabbdom
@@ -17,9 +17,10 @@ It's goals being:
1717
2. To be as fast as possible given (1).
1818
3. To be extensible.
1919

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.
2324

2425
---
2526

src/Halogen/VDom/DOM.purs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type VDomMachine eff a b = Machine (Eff eff) a b
3030

3131
type VDomStep eff a b = Eff eff (Step (Eff eff) a b)
3232

33+
-- | Widget machines recursively reference the configured spec to potentially
34+
-- | enable recursive trees of Widgets.
3335
newtype VDomSpec eff a w = VDomSpec
3436
{ buildWidget VDomSpec eff a w VDomMachine eff w DOM.Node
3537
, buildAttributes DOM.Element VDomMachine eff a Unit
@@ -38,6 +40,15 @@ newtype VDomSpec eff a w = VDomSpec
3840

3941
type VDomEffects eff = (dom DOM | eff)
4042

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+
-- | ````
4152
buildVDom
4253
eff a w
4354
. VDomSpec (VDomEffects eff) a w

src/Halogen/VDom/DOM/Prop.purs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import Halogen.VDom.Types (Namespace(..))
2727
import Halogen.VDom.Util as Util
2828
import Unsafe.Coerce (unsafeCoerce)
2929

30+
-- | Attributes, properties, event handlers, and element lifecycles.
31+
-- | Parameterized by the type of handlers outputs.
3032
data Prop a
3133
= Attribute (Maybe Namespace) String String
3234
| Property String PropValue
@@ -60,6 +62,9 @@ propFromInt = unsafeCoerce
6062
propFromNumber Number PropValue
6163
propFromNumber = unsafeCoerce
6264

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`.
6368
buildProp
6469
eff a
6570
. (a Eff (ref REF, dom DOM | eff) Unit)

src/Halogen/VDom/Machine.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ data Step m a b = Step b (Machine m a b) (m Unit)
2121
instance functorStepFunctor m Functor (Step m a) where
2222
map f (Step x m d) = Step (f x) (m >>> map (map f)) d
2323

24+
-- | Returns the output value of a `Step`.
2425
extract m a b. Step m a b b
2526
extract (Step x _ _) = x
2627

28+
-- | Runs the next step.
2729
step m a b. Step m a b a m (Step m a b)
2830
step (Step _ m _) = m
2931

32+
-- | Runs the finalizer associated with a `Step`
3033
halt m a b. Step m a b m Unit
3134
halt (Step _ _ h) = h
3235

src/Halogen/VDom/Types.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import Data.Newtype (class Newtype)
1818
import Data.Tuple (Tuple)
1919
import Unsafe.Coerce (unsafeCoerce)
2020

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.
2127
data VDom a w
2228
= Text String
2329
| Elem (ElemSpec a) (Array (VDom a w))

0 commit comments

Comments
 (0)