[PEAK] Laziness, terminology, and the Trellis API

Phillip J. Eby pje at telecommunity.com
Thu Mar 13 23:35:03 EDT 2008


At 03:04 AM 3/14/2008 +0200, Sergey Schetinin wrote:
>Looks very reasonable to me. One thing that seems to missing is API 
>to declare non-method observers, one can just create a Cell, but 
>then you need to get a value once to initialize the dependencies and 
>you still have to think about keeping a reference. Maybe it's a bad 
>idea but I keep creating rules from closures, so I created a 
>decorator to make it easier, maybe it's good enough to include in the core API:
>
>from peak.events.trellis import Cell
>
>__all__ = ['rule_for']
>
>def rule_for(ob):
>     add = ob.__dict__.setdefault(rule_for, []).append
>     def deco(m):
>         cell = Cell(m)
>         cell.value
>         add(cell)
>         return m
>     return deco
>
>
>To be used like this:
>
>...
>def track_status(self, status):
>     @rule_for(status)
>     def onstatus():
>         status.set(self.process.status)


I would just use an AddOn with a rule, myself.  See the AddOns 
library in the Cheeseshop.




More information about the PEAK mailing list