thomashoneyman / purescript-halogen-portal

Portals for Halogen: Render child components anywhere in the DOM
MIT License
26 stars 5 forks source link

Receiving inputs #4

Closed chrisdone closed 2 years ago

chrisdone commented 2 years ago

When I swap H.slot with portalAff, the component no longer receives updates after a render occurs.

Indeed, the H.Receive branch doesn't do anything with receive. One approach might be to pass an argument in to portal that would take an input and turn it into a query, but I was unable to make anything type check.

chrisdone commented 2 years ago

I achieved what I wanted via the mentioned approach:

 component ::
   forall query input output m n.
   MonadAff m =>
+  (input -> query Unit) ->
   m (NT n Aff) ->
   H.Component HH.HTML query (Input query input output n) output m
-component contextualize =
+component mkQuery contextualize =
   H.mkComponent
     { initialState
     , render
@@ -210,7 +198,9 @@ component contextualize =
       state <- H.get
       for_ state.io (H.liftAff <<< _.dispose)
       pure a
-    H.Receive input a -> pure a
+    H.Receive input a -> do
+      _ <- eval (H.Query (liftCoyoneda (mkQuery (input.input))) identity)
+      pure a
     H.Action output a -> do
       H.raise output

At least, it seems to be working properly.