Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#when:do API #257

Open
ELePors opened this issue May 23, 2023 · 5 comments
Open

#when:do API #257

ELePors opened this issue May 23, 2023 · 5 comments

Comments

@ELePors
Copy link

ELePors commented May 23, 2023

Hello, when you call a #when:do: on a BlElement, the method calls a #addEventHandlerOn:do: without returning the instance of eventHandler recorded. It must be returned in order do removal on some events handlers.

example :
self when: BlMouseMoveEvent do: [ :event | self mouseMovedTo: event ]
returns the receiver (self) of the message...

@tinchodias
Copy link
Collaborator

It happened to me once, I agree we can answer the handler.

Also, I wonder we need an additional change in this API... In Pharo 12, Announcer>>when:do: is deprecated in favor of Announcer>>when:do:for:, with a third argument. I'm not sure if the reason is the ephemerons, or the clean blocks.

@tesonep ?

@labordep
Copy link
Contributor

labordep commented Nov 1, 2023

How to remove a when:do: listener?
when:do: should return the listener to remove it later if necessary.

I propose to do that:

BlElement>>when: anEventClass do: aBlock
	^ self addEventHandlerOn: anEventClass do: aBlock

Of course this on TBlEventTarget trait

@labordep
Copy link
Contributor

labordep commented Nov 1, 2023

After to discuss with @plantec, it's appears than when:do: should be deprecated because this is not symmetric and a little confusing because the add handler is not clear.

@plantec
Copy link
Collaborator

plantec commented Nov 1, 2023

instead of when:do: one should use addEventHandler: as in:
clickHandler := (BlEventHandler
on: BlClickEvent
do: [ :event | do something ]).
self addEventHandler: clickHandler.

then one can remove the handler nicely with:
self removeHandler: clickHandler

@labordep
Copy link
Contributor

labordep commented Nov 1, 2023

when:doOnce: is ok because it manage the lifecycle of the event handler itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants