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.
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:
17172 . To be as fast as possible given (1).
18183 . 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
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ type VDomMachine eff a b = Machine (Eff eff) a b
3030
3131type 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.
3335newtype 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
3941type 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+ -- | ````
4152buildVDom
4253 ∷ ∀ eff a w
4354 . VDomSpec (VDomEffects eff ) a w
Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ import Halogen.VDom.Types (Namespace(..))
2727import Halogen.VDom.Util as Util
2828import Unsafe.Coerce (unsafeCoerce )
2929
30+ -- | Attributes, properties, event handlers, and element lifecycles.
31+ -- | Parameterized by the type of handlers outputs.
3032data Prop a
3133 = Attribute (Maybe Namespace ) String String
3234 | Property String PropValue
@@ -60,6 +62,9 @@ propFromInt = unsafeCoerce
6062propFromNumber ∷ Number → PropValue
6163propFromNumber = 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`.
6368buildProp
6469 ∷ ∀ eff a
6570 . (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)
2121instance functorStep ∷ Functor 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`.
2425extract ∷ ∀ m a b . Step m a b → b
2526extract (Step x _ _) = x
2627
28+ -- | Runs the next step.
2729step ∷ ∀ m a b . Step m a b → a → m (Step m a b )
2830step (Step _ m _) = m
2931
32+ -- | Runs the finalizer associated with a `Step`
3033halt ∷ ∀ m a b . Step m a b → m Unit
3134halt (Step _ _ h) = h
3235
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ import Data.Newtype (class Newtype)
1818import Data.Tuple (Tuple )
1919import 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.
2127data VDom a w
2228 = Text String
2329 | Elem (ElemSpec a ) (Array (VDom a w ))
You can’t perform that action at this time.
0 commit comments