[英]Editing and running Halogen applications from pulp psci
I am working on a small Purescript application that produces visualizations. 我正在开发一个小型的Purescript应用程序,该应用程序可以产生可视化效果。 My architecture is a bit non-traditional, however, and I'm having some issues. 但是,我的体系结构有点不传统,我遇到了一些问题。 Here's what I want: 这就是我想要的:
pulp psci -- --port 8080
and connect with a browser 启动pulp psci -- --port 8080
并连接浏览器 go
which accepts a definition of the visualization and renders it along with some controls 调用函数go
,该函数接受可视化的定义并将其与一些控件一起呈现 go
. 转到步骤2并使用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. 到目前为止,这种方法已经可以解决我的问题,但是我的问题是,反复调用go
并不会替换DOM的内容,而是将其添加到了DOM中。 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
的定义,我认为需要更改:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.