3

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?

The Red Fox
  • 810
  • 6
  • 12

2 Answers2

3

(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 [].
Heinrich Apfelmus
  • 11,034
  • 1
  • 39
  • 67
  • Oh right, I didn't realize it worked that way. I'll fix that then. Would be good to put that into the documentation though, since it doesn't make it clear that they shouldn't be usable after `delete`. – The Red Fox Apr 21 '17 at 11:17
2

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?

liminalisht
  • 1,243
  • 9
  • 11