简体   繁体   中英

Editing and running Halogen applications from pulp psci

I am working on a small Purescript application that produces visualizations. My architecture is a bit non-traditional, however, and I'm having some issues. Here's what I want:

  1. Launch pulp psci -- --port 8080 and connect with a browser
  2. Call a function go which accepts a definition of the visualization and renders it along with some controls
  3. See the results. Go back to the REPL and possibly create some new definitions.
  4. Go to step 2 and draw the new visualization with go .

This sort of works with what I have so far, but my problem is that repeated calls to go do not replace the contents of the DOM, but instead are added to them. This means that after a few calls I end up having many copies of all the controls and everything.

I realize this is a bit of a hack, but the only other way I can think to provide this kind of interactive interface is to implement an editor/parser and that's too much work Is there a way to avoid this?

Here's my definition of go , which I imagine needs changing:

go :: Vis -> Eff (HA.HalogenEffects ()) Unit
go vis = HA.runHalogenAff do
  body <- HA.awaitBody
  runUI checks vis body

After a lot of experimenting, I discovered that at least one seemingly reasonable workaround is to explicitly delete the old child nodes. I don't really know what's going on in the background (am I running a bunch of meaningless processes?) but this works for my purposes:

go :: VVis -> Eff (HA.HalogenEffects ()) Unit
go vis = HA.runHalogenAff do
  body <- HA.awaitBody
  let nb = htmlElementToNode body
  _ <- H.liftEff $ whileJust
    (firstChild (htmlElementToNode body))
    (\n -> removeChild n (htmlElementToNode body))
  runUI checks vis body

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