On Wed, Oct 22, 2008 at 3:20 PM, Derek Chen-Becker <[EMAIL PROTECTED]>wrote:

> Technically it lives in your session. The closure (not 100% sure that's the
> correct term):
>
> () => {cnt = cnt + 1; SetHtml("cnt_id", Text( cnt.toString))}
>
> Creates a function object (of type
> http://www.scala-lang.org/docu/files/api/scala/Function0.html) that is
> installed in your session via the "a()" method in Helpers. The object
> carries a reference to the instance of the cnt variable that was in scope
> when the closure was defined. When you reload your page you're really
> creating a whole new HelloFormAjax instance, with its own new cnt instance
> and a new closure instance. This is just the tip of the awesome power of
> closures in Scala :)
>

Awesome! Couldn't have explained it better myself.


>
>
> Derek
>
>
> On Wed, Oct 22, 2008 at 2:27 PM, didi <[EMAIL PROTECTED]> wrote:
>
>>
>> Hello,
>>
>> im Playing around with Lift Snippets and die Ajax Examples provided in
>> the Demo.
>> I've learned from the FAQ the a Snippet default lives for a request
>> time.
>>
>> Now i have following Ajax example:
>>
>> class HelloFormAjax {
>>  def sample = {
>>    var cnt = 0
>>
>>    <span>
>>    {
>>      a(() => {cnt = cnt + 1; SetHtml("cnt_id", Text( cnt.toString))},
>>          <span>Click me to increase the count
>>     (currently <span id='cnt_id'>0</span>)</span>)
>>    }</span>
>>  }
>> }
>>
>> Here is what i observed using Java Remote Debugger connecting my
>> Eclipse to Jetty:
>>
>> The cnt = 0 expression is executed once a request (Reload of the
>> Browser Page).
>>
>> Now I wonder where the cnt var lives during the Ajax calls.
>>
>> Thanks
>> Christian
>>
>>
>>
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

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

Reply via email to