Hi,
Le 13 mai 2013 à 11:42, Bahman Movaqar <
b.mo...@gmail.com> a écrit :
> Hi all,
>
> First of all, it's my first day with Nagare so please bear with me if I'm asking something naive.
>
> Following the tutorial, in part 4, after adding the AsyncRenderer, 'freeze' link for counter1 doesn't work.
You're right, the last step of the tutorial was wrong
> I'm curious as to what is the reason? How can I make it work?
The line:
h << self.counter1.render(xhtml.AsyncRenderer(h), model=None)
must be changed to:
h << self.counter1.render(xhtml.AsyncRenderer(h))
Because with the param `model=None`, we force the `counter1` component to always be rendered with its default view even if a previous `comp.becomes(counter, model='freezed')` action has set it to `freezed`. Without any `model` parameter, the `counter1` component is simply rendered with its currently set view.
The documentation is now fixed:
http://www.nagare.org/trac/wiki/NagareTutorial4?action=diff&version=12&old_version=11
> TIA,
> --
> Bahman
Thanks for the report,
Alain
# Tutorial #4, final step
#
# ----------------------------------------------------------
# File: counter.py
from nagare import presentation
class Counter(object):
def __init__(self):
self.val = 0
def increase(self):
self.val += 1
def decrease(self):
self.val -= 1
@presentation.render_for(Counter)
def render(counter, h, comp, *args):
h << h.div('Value: ', counter.val)
h << h.a('++').action(counter.increase)
h << '|'
h << h.a('--').action(counter.decrease)
h <<
h.br
h << h.a('freeze').action(lambda: comp.becomes(counter, model='freezed'))
return h.root
@presentation.render_for(Counter, model='freezed')
def render(counter, h, *args):
return h.h1(counter.val)
# ----------------------------------------------------------
# File: app.py
from nagare import component, presentation
from nagare.namespaces import xhtml
from counter import Counter
class App(object):
def __init__(self):
self.counter1 = component.Component(Counter())
self.counter2 = component.Component(Counter())
@presentation.render_for(App)
def render(self, h, *args):
h << self.counter1.render(xhtml.AsyncRenderer(h))
h <<
h.hr
h << self.counter2
return h.root
app = App