How to recreate an element in Threepenny GUI?

291 Views Asked by At

If I use the delete function on some Elements, how can I then recreate them (as in make them appear again)?

I have looked around the examples and documentation, but I couldn't find any function that would allow me to do this except maybe mkElement which requires me to pass it a String. However since I'm working with Elements getting the String that would create it would be a bit difficult.

So is there any way to do that?

2

There are 2 best solutions below

1
Heinrich Apfelmus On BEST ANSWER

(Library author here)

Actually the, delete function does more than just remove the element from the DOM tree — it tries to delete any references to it in the JS and Haskell side. Essentially the element is (should be) unuseable after a delete.

If you want to temporarily hide an element, you can

  • Hide it via the CSS display property.
  • Rest the children of the parent element, e.g. by element parent # set children [].
1
liminalisht On

Given that delete has the signature delete :: Element -> UI (), it follows that when you call delete, you have an Element in hand. Why can't you just hold onto this Element somewhere? (By which I mean maintain a reference to it in any number of ways.) Then just use (#+) :: UI Element -> [UI Element] -> UI Element to attach it as a child to another element later. If you just want it to reappear where it was before, you'd just attach it as a child to the very element that was its parent to begin with. Is this what you had in mind, or did I misunderstand the question?