Skip to content

Commit 34c032a

Browse files
authored
Merge pull request #27 from garyb/render-widget
Add "renderWidget"
2 parents 14ec580 + f245501 commit 34c032a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Halogen/VDom/Types.purs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Halogen.VDom.Types
22
( VDom(..)
3+
, renderWidget
34
, Graft
45
, GraftX(..)
56
, graft
@@ -39,6 +40,18 @@ instance bifunctorVDom ∷ Bifunctor VDom where
3940
bimap f g (Grafted a) = Grafted (bimap f g a)
4041
bimap f g a = Grafted (graft (Graft f g a))
4142

43+
-- | Replaces "widgets" in the `VDom` with the ability to turn them into other
44+
-- | `VDom` nodes.
45+
-- |
46+
-- | Using this function will fuse any `Graft`s present in the `VDom`.
47+
renderWidget a b w x. (a b) (w VDom b x) VDom a w VDom b x
48+
renderWidget f g = case _ of
49+
Text a → Text a
50+
Elem ns n a ch → Elem ns n (f a) (map (renderWidget f g) ch)
51+
Keyed ns n a ch → Keyed ns n (f a) (map (map (renderWidget f g)) ch)
52+
Widget w → g w
53+
Grafted gaw → renderWidget f g (runGraft gaw)
54+
4255
foreign import data GraftType Type Type
4356

4457
instance functorGraftFunctor (Graft a) where

0 commit comments

Comments
 (0)