[PEAK] Laziness, terminology, and the Trellis API

Sergey Schetinin maluke at gmail.com
Thu Mar 13 21:04:53 EDT 2008


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)


Phillip J. Eby wrote:
 > Anyway, I just wanted to toss this out there to get some feedback, see
 > if anybody has any comments, questions, complaints, etc.  :)




More information about the PEAK mailing list