Discussion:
on: in: eventTrigger and initialize
Bernd Eckardt
2005-12-02 11:41:37 UTC
Permalink
I have a CCollection as part of a CPlayer and a method triggering
changes in this collection with <on: changed in: collection>. This
works fine as long as I don't add anything to the collection from inside
the initilze method of the CPlayer. I expected that this changes also be
signalised as normal field changes in the initialize method. The reason
for that behaviour is the order of installing the scripts and triggers.
Is there a constraint to avoid such a constellation and bypass the
problems by using startscript to fill the collection or call the method
triggering the event by hand?

Bernd
Andreas Raab
2005-12-05 00:39:28 UTC
Permalink
Hi -

Yes, this will always happen when you change the value in a field. Let's
say you have a field and do something like:

onFooEvent
<on: testEvent in: foo>

and then do anything like:
newFoo := CPlayer new.
obj foo: newFoo.
newFoo signal: #testEvent.

The event method will not be triggered. More technically speaking the
update for the trigger only happens when the current cycle is completed
which makes sense for two reasons:
* foo might be stored into multiple times in which cases you might get
erranous events for a foo that's no longer there
* events signaled by/for foo become idempotent, e.g., the effect of
newFoo := CPlayer new.
obj foo: newFoo.
newFoo signal: #testEvent.
is the same as
newFoo := CPlayer new.
newFoo signal: #testEvent.
obj foo: newFoo.

To avoid the problem you are seeing you will need to react to a change
in the field itself, e.g., something like:

onFooChanged
"Foo has changed. Check whether we need to do anything."
<on: fooChanged>

and handle the (potential) effect that the event might have signaled.

BTW, the "classic" example for this are the onPlayerChanged methods in
the various widget costumes. They typically call many of the individual
change triggers since they must assume that the particular property has
changed, e.g., you'll see stuff like:

onPlayerChanged
<on: playerChanged>
self onLabelChanged. "assume label changed"
self onFontChanged. "assume font changed"

etc.

Cheers,
- Andreas
Post by Bernd Eckardt
I have a CCollection as part of a CPlayer and a method triggering
changes in this collection with <on: changed in: collection>. This
works fine as long as I don't add anything to the collection from inside
the initilze method of the CPlayer. I expected that this changes also be
signalised as normal field changes in the initialize method. The reason
for that behaviour is the order of installing the scripts and triggers.
Is there a constraint to avoid such a constellation and bypass the
problems by using startscript to fill the collection or call the method
triggering the event by hand?
Bernd
_______________________________________________
Tweak mailing list
http://impara.de/mailman/listinfo/tweak
Loading...