Re: Trellis on_commit and Performers

"Sergey Schetinin" <[email protected]>
Newsgroups gmane.comp.python.peak
Message-ID <[email protected]>
Much closer to have it all working, but two more issues.

First is that if the value is not subscribed to, it will return stale
data later. For example window position, a new frame might want to be
created at a position relative to parent, but a read of .position
would return a position where it was created, not current value.
Another layer with @compute depending on .watching should solve this
as well.

Second, things like this don't work:

class Test(trellis.Component):
    @trellis.maintain
    def value(self):
        return False

@trellis.atomically
def test():
    t1 = Test()
    t1.value = True

There's a good reason for that, but there's no need to initialize
.value on instance creation. @trellis.maintain(optional=True) seems to
do the trick, but isn't generally a bad idea to allow maintain rules
to be optional all? Surely in this case it's fine, but in my mind it's
not really a normal maintain rule, or is it?


This seems to work better:

    @trellis.compute
    def value(self):
        val = self._value
        if self.watching:
            return val
        return self.decode(self.wxread())

    @trellis.maintain(optional=True)
    def _value(self):
        if self.watching:
            evt = getattr(self.ob, self.attr.event_name)
            if evt is not None:
                if self.decode_event is not None:
                    return self.decode_event(evt)
        return self.decode(self.wxread())


Other than @maintain Effectors running three times instead of one
everything works great so far. Many thanks for your guidance.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.