Skip to content

Commit

Permalink
Add "renderWidget"
Browse files Browse the repository at this point in the history
  • Loading branch information
garyb committed Mar 20, 2019
1 parent 14ec580 commit 9a7e7cb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Halogen/VDom/Types.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Halogen.VDom.Types
( VDom(..)
, renderWidget
, Graft
, GraftX(..)
, graft
Expand Down Expand Up @@ -39,6 +40,15 @@ instance bifunctorVDom ∷ Bifunctor VDom where
bimap f g (Grafted a) = Grafted (bimap f g a)
bimap f g a = Grafted (graft (Graft f g a))

renderWidget a w x. (w VDom a x) VDom a w VDom a x
renderWidget f = case _ of
Text a → Text a
Elem ns n a ch → Elem ns n a (map (renderWidget f) ch)
Keyed ns n a ch → Keyed ns n a (map (map (renderWidget f)) ch)
Widget w → f w
Grafted g → Grafted $ unGraft (\(Graft fa fw v) →
graft (Graft identity identity (renderWidget f (bimap fa fw v)))) g

foreign import data Graft Type Type Type

instance functorGraftFunctor (Graft a) where
Expand Down

0 comments on commit 9a7e7cb

Please sign in to comment.