Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
44a49b07
Commit
44a49b07
authored
May 09, 2006
by
Philipp von Weitershausen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update docs, put reminder in there where to put LazyExpr in the future.
parent
d82fc6d1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
28 deletions
+12
-28
lib/python/Products/PageTemplates/DeferExpr.py
lib/python/Products/PageTemplates/DeferExpr.py
+12
-28
No files found.
lib/python/Products/PageTemplates/DeferExpr.py
View file @
44a49b07
...
@@ -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
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment