From 9a7e7cb316dc5566e72b70e2321e0277fc9de1c9 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Wed, 20 Mar 2019 23:11:05 +0000 Subject: [PATCH 1/3] Add "renderWidget" --- src/Halogen/VDom/Types.purs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Halogen/VDom/Types.purs b/src/Halogen/VDom/Types.purs index ac3c356..3166c2d 100644 --- a/src/Halogen/VDom/Types.purs +++ b/src/Halogen/VDom/Types.purs @@ -1,5 +1,6 @@ module Halogen.VDom.Types ( VDom(..) + , renderWidget , Graft , GraftX(..) , graft @@ -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 functorGraft ∷ Functor (Graft a) where From e0532a91941a243b505f786176311ab22c1003a9 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Wed, 20 Mar 2019 23:14:37 +0000 Subject: [PATCH 2/3] Add doc comment --- src/Halogen/VDom/Types.purs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Halogen/VDom/Types.purs b/src/Halogen/VDom/Types.purs index 3166c2d..77f7c84 100644 --- a/src/Halogen/VDom/Types.purs +++ b/src/Halogen/VDom/Types.purs @@ -40,6 +40,10 @@ 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 w x. (w → VDom a x) → VDom a w → VDom a x renderWidget f = case _ of Text a → Text a From f245501fd0ea4886e3b40c84ecdad5aae9484f8a Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Thu, 21 Mar 2019 00:24:42 +0000 Subject: [PATCH 3/3] Remap the input too during 'renderWidget' --- src/Halogen/VDom/Types.purs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Halogen/VDom/Types.purs b/src/Halogen/VDom/Types.purs index 77f7c84..9500cb5 100644 --- a/src/Halogen/VDom/Types.purs +++ b/src/Halogen/VDom/Types.purs @@ -44,14 +44,13 @@ instance bifunctorVDom ∷ Bifunctor VDom where -- | `VDom` nodes. -- | -- | Using this function will fuse any `Graft`s present in the `VDom`. -renderWidget ∷ ∀ a w x. (w → VDom a x) → VDom a w → VDom a x -renderWidget f = case _ of +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 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 + 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