5

To put it simple, I am looking for a way to display a Behaviour (UI Element).

My actual use-case is displaying a table, which can be filtered. So I have a function tableElement :: String -> UI Element (the String parameter being the filter condition) and an input field filterElement :: Element, which represents the filter. The most natural way for me to combine these would be something like this:

bFilter <- stepper "" (valueChange filterElement)
displaySomehow (fmap tableElement bFilter)

This is also the way it is done in Elm.

The closest thing I have found so far is using sink children, but that works only with [Element] and not with [UI Element]. Additionally I have to use a dummy element as parent or fiddle around with the remaining children.

What would be the best way to to implement something like this with threepenny-gui?

ipsec
  • 680
  • 4
  • 11

2 Answers2

2

(Author here)

Note that UI Element represents an action that, when executed, may create a new Element. You will have to execute the action to do the latter. Unfortunately, there is currently no way to do that completely within the FRP style, you will have to resort to the onChanges combinator to create the table anew whenever the filter changes. There, you can use set children.

Example:

onChanges bFilter $ \s -> do
    el <- tableElement s
    myTable # sink children [el]

The Bartab.hs and CRUD.hs examples may be relevant for your situation.

Heinrich Apfelmus
  • 11,034
  • 1
  • 39
  • 67
  • 1
    Well, this is unfortunate. I have the feeling this is somehow against the spirit of FRP. On the other hand, threepenny-gui is not a pure FRP library in the first place, I guess. Do you see any chance to make dynamic elements based on behaviours possible in the future? – ipsec Feb 16 '15 at 17:15
  • 1
    Yes, and yes. The plan is to integrate threepenny with reactive-banana at some point, and thus support *dynamic event switching*, which is the relevant concept needed here. – Heinrich Apfelmus Feb 16 '15 at 22:21
  • Sounds great, I'm looking forward to this. – ipsec Feb 17 '15 at 09:50
  • I've stumbled into the same issue, I'd also like this to be supported for maximum FRPness! :) – Wizek Nov 08 '15 at 01:09
0

You can use currentValue to obtain the UI Element from there you are (hopefully) in UI and can get the element for inclusion in the HTML.

Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166