question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array clone on DispatchEvent

See original GitHub issue

I just noticed that in the DispatchEvent function from the EventDispatcher the listeners array is cloned on every call https://github.com/mrdoob/three.js/blob/dev/src/core/EventDispatcher.js#L71. That doesn’t look like nice for the GC. Is there any specific reason that I may be missing why this is working that way instead of just removing that line and iterate directly on listenerArray? /cc @mrdoob

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gkjohnsoncommented, May 9, 2019

It could be possible for one of the callbacks to remove any of the other ones, right? Not just itself? So no matter what order you traverse the callbacks in you’ll wind up changing the behavior of the class in some cases if you don’t clone the array.

1reaction
fernandojsgcommented, May 9, 2019

That makes sense yep, what about using unshift instead of push? That will make the order correct even if iterating back-to-front https://jsfiddle.net/8nwqaept/

I guess it could be nice to benchmark unshift performance impact versus slice()+push 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to clone or re-dispatch DOM events? - Stack Overflow
I've just put together a module on npm called clone-event which essentially wraps the functionality described in this answer, which is what I ......
Read more >
frame_support::dispatch::marker::Copy - Rust - Docs.rs
The implementation of Clone can provide any type-specific behavior necessary to duplicate values safely. For example, the implementation of Clone for String ...
Read more >
Methods of Javascript Copy Array with Examples - eduCBA
1. Slice Method · array: The original array that you wish to copy to the other array. · newArray: This is the new...
Read more >
ES6 Way to Clone an Array | SamanthaMing.com
When we need to copy an array, we often times used slice. But with ES6, you can also use the spread operator to...
Read more >
JavaScript Array copyWithin() Method - W3Schools
Copy the first two array elements to the last two array elements: ... The copyWithin() method copies array elements to another position in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found