Behaviors and the message path
Mark Waddingham
mark at livecode.com
Fri Dec 9 12:56:20 EST 2016
On 2016-12-08 21:23, Bleiler, Timothy wrote:
> I’m curious about what appears to me to be a confusing aspect of the
> implementation of behaviors. In short, behaviors have characteristics
> of an isolated, local extension of the message path AND
> characteristics of a concatenation of the parent control’s script. I’m
> raising the issue for two reasons: 1) to clarify how to explain
> behaviors to someone new to Livecode or just learning about the
> feature and 2) to question if all the features of behaviors are
> intentional or if some might be accidents of implementation and
> therefore may be eliminated in the future.
The design of behaviors was to allow sharing of code amongst controls.
Indeed, the premise was that, given any control A, the following steps
would cause no change in functionality of A:
1) create button B
2) set the script of button B to the script of control A
3) set the script of control A to empty
4) set the behavior of control A to the long id of button B
In order for this to be the case, two things have to be true:
1) Behaviors must keep a 'private' copy of their script locals for
each control using that behavior
2) 'me' must always resolve to the control using the behavior, even
when in the behavior script
The key thing here is that when you call a handler from a script, unless
it is bound to a private handler in the same script, the request will
pass through the message path targeting 'me' - so first frontScripts
will trigger, then me, then the owner of me etc. Rule (2) preserves this
semantic for behaviors and, indeed, codifies the fact that behaviors
aren't really objects - they are script extensions (for want of a better
term).
The reason you see friction between what happens in the behavior chain,
and what happens in the ownership chain simply comes down to the fact
that when considering the ownership chain you are dealing with multiple
distinct objects and thus there is more than one object which is being
targetted by messages. In contrast, when you are considering the
behavior chain there is only ever a single real object - the control
using the chain - thus there is only one thing that can be the target of
message sends.
Hope this helps,
Mark.
--
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode
mailing list