0

I am trying to get my head around compiled splices. With previouse help I can compile and render some usefull results. I don't fully understand the way it works though.

In interpreted mode, the algorithm is simple: construct root, call handler function given the mapped url, pull data from DB, construct and bind splices out of pulled data, insert them into heist and call the apropriate template.

It is all upside down in compiled mode. I map url directly to cRender and don't call a handler. So I assume all the splice constructing and data processing functions are called at load time.

So my question is when is the database called? Does this happen at load time too? It is just the sequence of events that I don't understand.

Since splice construction is independent of a particular template rendering, does this mean the splice binding tags are unique accross the whole application?? Are they like global variables?

Thanks

mightybyte
  • 7,282
  • 3
  • 23
  • 39
r.sendecky
  • 9,933
  • 9
  • 34
  • 62

1 Answers1

3

Yes, you are pretty much correct. Although I wouldn't say they are like global variables. They are more like global constants, or a global API. I view compiled splices as an API that your web designer can use to interact with dynamic data.

Compiled splices allow you to insert holes into your markup that get filled with data at runtime. At load time the running monad is HeistT n IO. But at run time the running monad is RuntimeSplice n. So if you're looking at the compiled Heist API, it's very easy to see where the runtime code like database functions need to be: in the RuntimeSplice n monad.

mightybyte
  • 7,282
  • 3
  • 23
  • 39
  • Makes sense. The runtime vs loadtime is pretty much clear.In a big application though, one would need quite a lot of unique global constants. So we might end up with weird long splice tags like "admin_category_users_id", don't you think? – r.sendecky Oct 26 '13 at 17:56
  • Yes. I think that's unavoidable complexity. – mightybyte Oct 27 '13 at 13:57
  • @mightybyte But many of those tags would be bound to subsplices linked to a top-level splice using `withLocalSplices` and related functions. They wouldn't be truly global, would they? Perhaps one could even employ "dummy top-level splices" that just wrapped other splices and worked as a replacement for namespaces... would that degrade performance? – danidiaz Oct 27 '13 at 15:10
  • @DanielDíazCarrete Yes, you're correct. A global splice might be something like `recentPosts`, but `postTitle`, `postAuthor`, and `postBody` would be local splices bound by the `recentPosts` splice and not available outside it. That definitely cleans up the namespace a bit. I'm not sure how much introducing dummy "namespace splices" would affect performance. With compiled Heist I don't think it would be too bad. – mightybyte Oct 27 '13 at 18:24