[Cuis-dev] triggering event with argument, emitter or listener last word?

Juan Vuletich juan at cuis.st
Mon Jul 28 09:08:58 PDT 2025


Hi Hilaire,

I don't know what was the expected behavior when that code was written. 
I think it comes from Squeak and is like 24 years old.

I think the behavior you expect makes sense: When someone triggers an 
event, it includes the 'default' arguments, but whoever subscribed to it 
specifying which selector to use, if they also specify arguments, then 
those arguments should be used instead.

The attach is my code for this. It doesn't seem to affect the base image 
at all, but I can't say about external packages.

Everybody, please take a look and try it. If nobody sees a problem, I'll 
push it.

Thanks,

On 19/07/2025 8:24 AM, Hilaire Fernandes via Cuis-dev wrote:
>
> Hi,
>
> I have this situation where an *objectA* can emit event with a default 
> argument (*self*):
>
>     FilePreviewMorph>>doubleClick: event localPosition: position
>         self triggerEvent: #doubleClick with: *self *
>
> And the listening *objectB* wants to be notified with a different 
> argument (*fileEntry*)
>
>     fileView when: #doubleClick send: #open: to: self with: *fileEntry*].
>
> However when the event is triggered in *objectA* the optional prefered 
> argument by *objectB* (fileEntry) is not used. It is still the *self* 
> argument.
>
> Is it the expected behavior?
>
> The behavior is revealed here:
>
>
> arguments contains the fileEntry but it is ignored as show the value 
> of argsToUse.
>
> Change in method bellow adjust this behavior. Not sure it is what is 
> expected.
>
> collectArguments: anArgArray     "Private"     | staticArgs |     
> staticArgs := self arguments.     ^(anArgArray size = staticArgs size) 
>         ifTrue: [*staticArgs asNewArra*]         ifFalse:             
> [(staticArgs isEmpty                 ifTrue: [ staticArgs := Array 
> new: selector numArgs]                 ifFalse: [staticArgs 
> asNewArray] )                     replaceFrom: 1                     
> to: (anArgArray size min: staticArgs size)                     with: 
> anArgArray                     startingAt: 1]
>
> Thanks
>
> Hilaire
>
> -- 
> http://mamot.fr/@drgeo
>
-- 
Juan Vuletich
www.cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250728/5050b3f7/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QcSmOQvTsvdvH4tp.png
Type: image/png
Size: 87632 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250728/5050b3f7/attachment-0001.png>
-------------- next part --------------
'From Cuis7.5 [latest update: #7385] on 28 July 2025 at 12:36:44 pm'!

!MessageSend methodsFor: 'private' stamp: 'jmv 7/28/2025 11:01:22'!
collectArguments: anArgArray
	"Arguments set when builing the receiver (i.e. set when registering for an event)
	take precedence over anArgArray (i.e. set when triggering the event).
	If you want to use arguments set at trigger event time, set to an empty array, or set individual elements to nil."

	| staticArgs answer |
	staticArgs := self arguments.
	answer := Array new: selector numArgs.
	1 to: answer size do: [ :i | | each |
		each := staticArgs at: i ifAbsent: nil.
		each isNil ifTrue: [
			each := anArgArray at: i ifAbsent: nil ].
		answer at: i put: each ].
	^answer! !


!MessageSend class methodsFor: 'instance creation' stamp: 'jmv 7/28/2025 11:10:37'!
receiver: anObject selector: aSymbol arguments: anArray
	"Note: Arguments set here will take preceence over those set when doing #valueWithArguments: and #triggerEvent:withArguments:. If you want them to take precedence, pass here #() or individual nil elements in anArray. See #collectArguments:"

	^ self new
		receiver: anObject;
		selector: aSymbol;
		arguments: anArray! !


!WeakMessageSend methodsFor: 'private' stamp: 'jmv 7/28/2025 11:01:41'!
collectArguments: anArgArray
	"Arguments set when builing the receiver (i.e. set when registering for an event)
	take precedence over anArgArray (i.e. set when triggering the event).
	If you want to use arguments set at trigger event time, set to an empty array, or set individual elements to nil."

	| staticArgs answer |
	staticArgs := self arguments.
	answer := Array new: selector numArgs.
	1 to: answer size do: [ :i | | each |
		each := staticArgs at: i ifAbsent: nil.
		each isNil ifTrue: [
			each := anArgArray at: i ifAbsent: nil ].
		answer at: i put: each ].
	^answer! !


!WeakMessageSend class methodsFor: 'instance creation' stamp: 'jmv 7/28/2025 11:11:17'!
receiver: anObject selector: aSymbol arguments: anArray
	"Note: Arguments set here will take preceence over those set when doing #valueWithArguments: and #triggerEvent:withArguments:. If you want them to take precedence, pass here #() or individual nil elements in anArray. See #collectArguments:"

	^ self new
		receiver: anObject;
		selector: aSymbol;
		arguments: anArray! !



More information about the Cuis-dev mailing list