I didn't see Tim's blog post, but another option is to bind in two passes. 
First bind the outer level: b1:link should become an SHtml.link, preserving the 
same set of child elements. So here use a NodeSeq function: kids => 
SHtml.link(..., kids). Then pass the resulting NodeSeq to a bind invocation 
that transforms your other elements.
You can place this in one statement, by using one call to bind as the NodeSeq 
argument to the other call. And you can use the implicit in BindPlus to chain 
bind calls:
xhtml.bind("prefix", bindParams ... ).bind("pre2", ...)
That said, I think there is a fundamental, inevitable tension between 
separation of view and logic, and repetition (not really your point). I tried 
to address this, as it applies to Mapper fields, to a small extent in 
ModelView. However if anyone has better ideas of how to do things I'm very 
interested to hear!



-------------------------------------
Timothy Perrett<timo...@getintheloop.eu> wrote:


Take a look at:

http://logji.blogspot.com/2009/09/composable-bindings-in-lift.html

and then:

http://logji.blogspot.com/2009/10/composable-bindings-in-lift-part-ii.html

Sounds like this could provide a more flexible implementation pattern for your 
use case.

Cheers, Tim


On 11 Nov 2009, at 18:21, aw wrote:

> 
> OK, your suggestion definitely makes the snippet code more readable,
> but I fear I didn't make my point clear because the snippet code still
> is highly coupled with the view layout.
> 
> Imagine that I want to change my view from this:
> 
> <a href="next">
>    <span class="name">name</span>
>    <span class="comment">description</span>
>    <span class="arrow"/>
> </a>
> 
> to this:
> 
> <span class="name">name</span>
> <span class="comment">description</span>
> <a href="next">
>    <span class="arrow"/>
> </a>
> 
> This would mean that I need to change my template from:
> 
> <b1:link>
>    <span class="name"><b2:name/></span>
>    <span class="comment"><b2:description/></span>
>    <span class="arrow"/>
> </b1:link>
> 
> to this:
> 
> <span class="name"><b:name/></span>
> <span class="comment"><b:description/></span>
> <b:link>
>    <span class="arrow"/>
> </b:link>
> 
> And then I need to update my code from:
> 
> bind("b1", xhtml",
>   "link" -> kids => SHtml.link("next", () => clicked(b),
>   bind("b2", kids, "name" -> b.name.is, "description" ->
> b.description.is
> )))
> 
> to something like this:
> 
> bind("b", xhtml",
>   "name" -> b.name.is,
>   "description" -> b.description.is,
>   "link" -> kids => SHtml.link("next", () => clicked(b))
> )))
> 
> 
> My complaint is that reorganizing the view is tending to require code
> changes at the snippet level.  And that just doesn't seem right to me.
> 
> At first, I thought that I could leverage the recursive nature of
> snippets.  In other words, I thought I could avoid the b1 and b2
> binding keys and simply use b, then when the first round contained
> more b variables to bind, it would recurse.  Alas, this didn't work
> (I'm sorry, but I don't recall the error message).  But this was what
> I was thinking:
> 
> <b:link>
>    <span class="name"><b:name/></span>
>    <span class="comment"><b:description/></span>
>    <span class="arrow"/>
> </b:link>
> 
> or this:
> 
> <span class="name"><b:name/></span>
> <span class="comment"><b:description/></span>
> <b:link>
>    <span class="arrow"/>
> </b:link>
> 
> and the code would remain this:
> 
> bind("b", xhtml",
>   "name" -> b.name.is,
>   "description" -> b.description.is,
>   "link" -> kids => SHtml.link("next", () => clicked(b))
> )))
> 
> 
> > 
> 




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to