update docs, put reminder in there where to put LazyExpr in the future.

parent d82fc6d1
...@@ -10,32 +10,16 @@ ...@@ -10,32 +10,16 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
"""Defer and Lazy expression handler """Lazy expression handler
defer expressions can be usesd for a design pattern called deferred evaluation. A lazy expressions is implemented similarly to the defer expression
but has a different result. While a defer expression is evaluated
Example: every time it is used according to its context a lazy expression is
evaluted only the first time it is used. Lazy expression are known
<div tal:define="xis defer:string:x is $x"> under the name lazy initialization of variables, too. A common use
<p tal:repeat="x python:range(3)" case for a lazy expression is a lazy binding of a costly expression.
tal:content="xis"></p> While one could call an expression only when it's required it makes
</div> sense to define it only one time when it could be used multiple times.
Output:
<div>
<p>x is 0</p>
<p>x is 1</p>
<p>x is 2</p>
</div>
A lazy expressions is implemented in a similar way but has a different result. While
a defer expression is evaluated every time it is used according to its context a lazy
expression is evaluted only the first time it is used. Lazy expression are known
under the name lazy initialization of variables, too.
A common use case for a lazy expression is a lazy binding of a costly expression.
While one could call an expression only when it's required it makes sense to define
it only one time when it could be used multiple times.
Example Example
...@@ -46,11 +30,11 @@ Example ...@@ -46,11 +30,11 @@ Example
</div> </div>
""" """
from zope.tales.expressions import DeferWrapper, DeferExpr from zope.tales.expressions import DeferWrapper, DeferExpr
# lazy expression
_marker = object() _marker = object()
# TODO These should really be integrated into the Zope 3 ZPT
# implementation (zope.tales)
class LazyWrapper(DeferWrapper): class LazyWrapper(DeferWrapper):
"""Wrapper for lazy: expression """Wrapper for lazy: expression
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment