Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Um, I'm not sure it's a good idea to alter the event object after it was dispatched. Users could work with the event object not just within the event listener. They could save the event and work with it later on. In this case it would be unexpected when
target
is suddenlynull
.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 see your point, although anyone being called knows what target is (this), in the listener functions. Is target used anywhere within Three? I can't see any obvious uses.
An alternative would be to zap it specifically in the Object3D.remove() method after the dispatch call. In those cases anyone saving the event object could get surprises anyway since it would be shared with other _removed events after that point.
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 was thinking the same thing but if that's the case any reused event definitions like this would be problematic because
target
will get overwritten with every subsequent call. TrackballControls, TransformControls, OrbitControls and I'm sure others all use this same pattern.These events were originally moved to be reused in order to save on memory allocation (see #17224, #17134 (comment)) but I missed that the object was modified in the
dispatchEvent
function. I personally am okay with denoting that an event is only valid during the execution of the callback, which would allow us to save memory allocation in quite a few other places.Setting the target to
null
in thedispatchEvent
function would change the functionality relative to the built relative to theEventTarget.dispatchEvent
function, though, so it might be more sensible to set target to null in theremove()
function, instead.Uh oh!
There was an error while loading. Please reload this page.
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've totally forgot that
three.js
code already reuses event objects...In this case, I prefer whatever @mrdoob likes. Also note that this class comes from a separate github repo. It could be useful to make changes also there: https://github.com/mrdoob/eventdispatcher.js/