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
Safe EventDispatcher #6064
Safe EventDispatcher #6064
Conversation
The problem with this solution is that every method is recreated for every object it uses. It isn't just the listeners object. This makes the objects heavier that they should be. |
The |
This is just a suggestion. The current implementation of EventDispatcher is intrusive. It sticks `_listeners` on object it's being added to. If that object already has a `_listeners` your out of luck. Above is a non intrusive implementation for your consideration. The `listeners` collection is not public whatsoever. I [tested them on jsperf and it's the same speed on chrome and significantly faster on Firefox](http://jsperf.com/event-dispatching) I didn't expose `dispatchEvent` to the public API of `TypedGeometry` because it seemed to me users of `TypedGeometry` shouldn't be able to dispatch events but of course that could be exposed too. Anyway, just passing it on as a suggestion. I'm learning JS as I go and finding that what I learned at Google was wrong :P They use their Closure Compiler and they basically treat JavaScript like Java and expect the compiler to make things semi safe but JavaScript can be safe all by itself so I'm slowly learing more JavaScripty ways.
not really becuase nearly every object has them (All object3ds, material, geometry) |
That's still thousands of objects. Not even the memory of 1 texture. |
The examples of this pullrequest are now built and visible in threejsworker. To view them, go to the following link: |
3 similar comments
The examples of this pullrequest are now built and visible in threejsworker. To view them, go to the following link: |
The examples of this pullrequest are now built and visible in threejsworker. To view them, go to the following link: |
The examples of this pullrequest are now built and visible in threejsworker. To view them, go to the following link: |
This is just a suggestion.
The current implementation of EventDispatcher is intrusive. It sticks
_listeners
onobject it's being added to. If that object already has a
_listeners
your out of luck.Above is a non intrusive implementation for your consideration. The
listeners
collection is not public whatsoever.
I tested them on jsperf and it's the same speed on chrome and significantly faster
on Firefox
I didn't expose
dispatchEvent
to the public API ofTypedGeometry
because itseemed to me users of
TypedGeometry
shouldn't be able to dispatch events butof course that could be exposed too.
Anyway, just passing it on as a suggestion. I'm learning JS as I go and finding that what I learned
at Google was wrong :P They use their Closure Compiler and they basically
treat JavaScript like Java and expect the compiler to make things semi safe but
JavaScript can be safe all by itself so I'm slowly learing more JavaScripty
ways.