[PEAK] Laziness, terminology, and the Trellis API
Sergey Schetinin
maluke at gmail.com
Thu Mar 13 23:42:09 EDT 2008
Phillip,
I'm using AddOns a lot, and in fact was using it here as well, but
that's not the issue. I just think that a similar decorator would be
generally useful.
P.S. Great libraries, always a pleasure to use and learn about. Thanks a
lot.
Phillip J. Eby wrote:
> 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