Skip to content

Commit

Permalink
Merge pull request #27 from garyb/render-widget
Browse files Browse the repository at this point in the history
Add "renderWidget"
  • Loading branch information
garyb authored Mar 21, 2019
2 parents 14ec580 + f245501 commit 34c032a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 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,18 @@ 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))

-- | Replaces "widgets" in the `VDom` with the ability to turn them into other
-- | `VDom` nodes.
-- |
-- | Using this function will fuse any `Graft`s present in the `VDom`.
renderWidget a b w x. (a b) (w VDom b x) VDom a w VDom b x
renderWidget f g = case _ of
Text a → Text a
Elem ns n a ch → Elem ns n (f a) (map (renderWidget f g) ch)
Keyed ns n a ch → Keyed ns n (f a) (map (map (renderWidget f g)) ch)
Widget w → g w
Grafted gaw → renderWidget f g (runGraft gaw)

foreign import data Graft Type Type Type

instance functorGraftFunctor (Graft a) where
Expand Down

0 comments on commit 34c032a

Please sign in to comment.