简体   繁体   中英

Do not run an halogen component when an html element is not present

I'm absolutely new to purescript and halogen. I'm trying to display an halogen component (myButton) when an html element exists, and do nothing otherwise.

displayButton :: Eff (HA.HalogenEffects ()) Unit
displayButton = HA.runHalogenAff do
  containerElement <- HA.selectElement (QuerySelector "#halogen-button")
  case containerElement of
    Nothing -> ???
    Just element -> runUI myButton unit element

I don't know what code to put in the Nothing clause so that my code type checks and do nothing in that case.

pure unit is the "do nothing" you could put in. You can also use for_ to make this a little nicer:

for_ containerElement \element ->
  runUI myButton unit element

Which, if you take currying into account is the same as:

for_ containerElement (runUI myButton unit)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM