简体   繁体   English

从解释到编译抢劫

[英]Going from interpreted to compiled heist

I don't seem to be able to grasp the compiled heist concept. 我似乎无法掌握编译的抢劫概念。 There are no examples on the net whatsoever. 网上没有任何例子。 How would I go about changing simple code snippets from interpreted to compiled. 我将如何将简单的代码片段从解释更改为已编译。

For instance: 例如:

listUsersH :: AppHandler ()
listUsersH = do
  users <- liftIO $ getColList "users"
  let userListS = mapSplices userLinkS users
  heistLocal (bindSplice "users" userListS) $ render "list-users"
  where
    userLinkS d = runChildrenWithText [("user",T.pack $ at "uname" d)]

How would I do the simple combination of "runChildren", "mapSplices", "bindSplice" and "render" with compiled heist? 如何使用编译的抢劫执行“runChildren”,“mapSplices”,“bindSplice”和“render”的简单组合?

I understand that the concept is different and there is no "heistLocal" .. But I need to go back now and re-learn how to do the basic things like displaying a bunch of records in a "for each" loop manner. 我知道这个概念是不同的,并且没有“heistLocal”..但我现在需要回过头来重新学习如何做一些基本的事情,比如以“for each”循环方式显示一堆记录。 Can someone clarify this and show a simple example like the one above but with compiled heist? 有人可以澄清这一点,并显示一个简单的例子,如上面的那个,但编译抢劫?

At the moment I dont even know how to do simple variable substitution with compiled heist. 目前我甚至不知道如何使用编译的抢劫进行简单的变量替换。 For instance, this: 例如,这个:

simpleString = "Insert me..."
insertString = heistLocal (bindSplices spl) $ render "tst"
where
  spl = [("var", textSplice simpleString)]

Please, someone help me with the basics or point me to a location with some minimal examples. 请有人帮助我完成基本操作,或者将我指向一个带有一些最小例子的位置。 I did read the snap web site docs. 我确实阅读了快照网站文档。

Compiled splices are definitely more difficult to work with. 编译的拼接肯定更难以使用。 For one, all splices must be statically bound up front. 首先,所有拼接必须在前面静态绑定。 This requires a pretty significant shift in mindset. 这需要一种非常重要的思维转变。 Before, using heistLocal you could view splices as things with a limited scope that could be bound whenever needed. 之前,使用heistLocal,您可以将拼接视为具有有限范围的事物,可以在需要时绑定。 You could make decisions in handlers using the information in the request and then bind splices accordingly. 您可以使用请求中的信息在处理程序中做出决策,然后相应地绑定拼接。 You can still do similar things with compiled splices, but it requires an inversion of control. 您仍然可以使用编译的拼接执行类似的操作,但它需要反转控制。 Now you have to do that kind of dynamic request-based decision making inside the splice (which is a monad transformer around your handler monad, so you still have access to handler functions). 现在你必须在splice中做这种基于请求的动态决策(这是你的处理程序monad周围的monad变换器,所以你仍然可以访问处理函数)。

I recommend thinking of compiled splices as global resources that you are making available to your web designers that they can use on any page however they see fit. 我建议将编译的拼接视为您可以提供给Web设计人员的全局资源,以便他们可以在任何页面上使用,但他们认为合适。 Viewing splices in this way has a couple advantages. 以这种方式查看接头有几个优点。 First, it makes them more orthogonal and composable than with specialized splices bound with heistLocal. 首先,与使用heistLocal绑定的专用拼接相比,它使它们更正交和可组合。 Second, it makes debugging easier, because you never have to worry about whether the splice has been bound or not. 其次,它使调试更容易,因为您永远不必担心接头是否已被绑定。

But the biggest difficulty of compiled splices is caused by the split between load time and runtime and what that means for splice functions. 但编译拼接的最大困难是由加载时间和运行时间的分割以及拼接功能的意义所引起的。 We talk about this a little in the last section of our wiki page about migrating to Heist 0.10 . 我们在维基页面的最后一节中讨论了有关迁移到Heist 0.10的内容 We also have a longer discussion of the "why" behind this. 我们还对这背后的“原因”进行了较长时间的讨论

We're also still working on improving the API for compiled Heist. 我们还在努力改进编译Heist的API。 We're very close to finishing Heist 0.13 which significantly simplifies the API and should help to make things more understandable. 我们非常接近完成Heist 0.13,这大大简化了API,并且应该有助于使事情更容易理解。 The code currently in the new-api branch on github is pretty close to being ready for release. 目前在github上的new-api分支中的代码非常接近准备发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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