-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Rename methods and fields to get entities associated with observers to reduce confusion #19609
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
base: main
Are you sure you want to change the base?
Rename methods and fields to get entities associated with observers to reduce confusion #19609
Conversation
self.trigger.target | ||
/// | ||
/// Note that if event bubbling is enabled for your event type, this may not be the entity that the event was originally targeted at. | ||
/// Instead, this is the entity that the event is *currently* targeted at, which may have changed due to propagation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯 helpful
/// | ||
/// Note that if event bubbling is enabled for your event type, this may not be the entity that the event was originally targeted at. | ||
/// Instead, this is the entity that the event is *currently* targeted at, which may have changed due to propagation. | ||
pub fn entity(&self) -> Option<Entity> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the intent is to revisit #18710 after this PR, but these properties are so tightly related that I think we kinda need to consider their naming together. If current_target
is entity
, would target
be something like original_entity
?
I see that this was bikeshed in #19263, but personally, I'm also not a huge fan of the name entity
.
- It doesn't indicate what entity it is. In this case, there would be three options: the original target, the entity the event was propagated to, and the observer entity. Judging purely based on the
entity
name, without looking at docs or the other methods, which one is it? To me, this is not self-evident. - I would personally expect the "shorter" name, whether
entity
ortarget
, to be the entity the event was originally targeting, not the entity the event was propagated to. If I trigger an event on A, and it is propagated to B, I would expect that the target was still A, and the event was just forwarded to be read by another observer. I was surprised to see that this is not the case. - Using the short name for the current target is opposite to web conventions where
target
is the original target andcurrentTarget
is the element the event was bubbled to. I'm aware we don't care too much about following web conventions, but just noting that there is a disconnect, and I personally find the web's semantics to be clearer and more generally useful here.
So my personal preference would be to use target
and current_target
like proposed in #18710. Or current_target
could also be something like observed
or observer_target
, but I'm not sure if that's clearer.
Aside 1: The lack of an easy way to get the original target is the reason I don't support bubbling collision events to rigid bodies in Avian yet. It's important to know which collider the event originally came from, and that cannot be determined with the current observer API.
Aside 2: It feels a bit weird to use a different naming here than in ObserverTrigger
, feels like they should be named the same.
I think |
Objective
Our various methods to get entities associated with observers can be confusing, and don't distinguish well between the common and rare cases.
Target::target
andTarget::target()
return different entities #17112.Trigger
to provide theEntity
on which an event w… #18710, which will need to be revisited.Solution
On::observer
->On::observer_entity
On::target
->On::entity
Pointer::target
->Pointer::original_target
ObserverTrigger::target
->ObserverTrigger::current_target