[Q]: Update: mechanism

Ned Konz ned at bike-nomad.com
Tue Dec 3 04:18:14 UTC 2002


On Monday 02 December 2002 06:56 am, Thierry Reignier wrote:

> What is the use of the "with:" part in when:send:to:with: as
> well as the "withArguments:" part in when:send:to:withArguments: ?
> since when I register my interest I don't have a clue
> what parameter I shall pass. I just know what selector to pass
> in "send:"
>
> Example: I want a morph to signal a selection by passing the
> selected item to my model. During initialisation of my morph I
> would call:
>    self when: #itemSelected send: #selectItem: to: aModel with: ??
> and when the morph handles the selection it sends:
>   self trigger: #itemSelected with: self seletedMorph model
>
> but here I did not use the "with:" part of the when:.... and
> it worked when I tried it.

the initial arguments you pass supply the default trailing arguments. 
They are overwritten starting at index 1 with any arguments provided 
to triggerEvent:* (see collectArguments:).

triggerEvent:with: x
is the same as triggerEvent:withArguments: { x }.

That is, it's a shortcut for sending a single argument.

> Question 2:
> -----------
> with the old mechanism (change: aSelector and update: aSelector)
> my model did not need to implement aSelector if the
> corresponding check was not implemented in the update: method.
>
> But with the new mechanism my model MUST implement aSelector.
> Why not checking if my model "respondsTo: aSelector" in
> when:send: ... , if not then do not register it ... to give the
> same funtionality as the old mechanism?

Easier... there are triggerEvent...ifNotHandled: [ ] variants so that 
you don't have to check first.

There a couple of problems with checking with respondsTo: at 
registration time:

* your item may later get the ability to handle the selector
* respondsTo: doesn't answer true for everything an object can respond 
to (because of doesNotUnderstand: hacks).

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE




More information about the Squeak-dev mailing list