[PEAK] Read/write delegation

Phillip J. Eby pje at telecommunity.com
Tue Feb 24 20:50:57 EST 2004


At 02:48 PM 2/24/04 -0800, John Landahl wrote:
>When using binding.Delegate, reading a delegated property works just fine, 
>but property assignments don't seem to get propagated.  The following code...
>
>   from peak.api import binding, config
>
>   r = config.makeRoot()
>
>   class A(binding.Component):
>       x = binding.Make(lambda: 1)
>
>   class B(binding.Component):
>       x = binding.Delegate('a')
>       a = binding.Make(A)
>
>   b = B(r)
>   print b.x, b.a.x
>
>   b.x = 2
>   print b.x, b.a.x
>
>..prints '1 1\n2 1', indicating that 'b.x = 2' did not get propagated to 
>b.a.x.  Is this by design?

Yes.  'x=binding.Delegate("y")' is almost exactly equivalent to 
'x=binding.Obtain("y/x")', except that you can also say:

      x = z = q = binding.Delegate("y")

in place of saying:
      x = binding.Obtain("y/x")
      z = binding.Obtain("y/z")
      q = binding.Obtain("y/q")

See 'peak help binding.Delegate' for more details.




More information about the PEAK mailing list