Description
The hand-controls component is a bit creaky--as it mentions in its own comments, it was originally just a proof of concept. It seems incomplete; as issue #4596 points out, the events are problematic, and the 'color' property doesn't affect the mesh. It also has a lot of room for improvement in terms of not being sufficiently dry, being written in a bit of an old fashioned style, and not being written in a way that is at all conscious of the effects on garbage collection.
When writing a version of this component for NAF, I went ahead and gave the component an overhaul, and ended up with this:
Would a pull request be welcome to add these changes over to core? Any comments on improving this code? Should I just make a pull request and we work from there?
Note: lines 20-40 are NAF-specific and can be ignored.
As you'll see, I have been working on a code style that minimizes garbage collection. You can see this in the str
property and the this.Y[this.Z]
pattern. (Because of other quiet object re-use patterns in A-Frame, there are very tricky pitfalls that show up when just assigning properties itself).
I know it's unorthodox; I'd love feedback on a cleaner way to write this code, if you have ideas. If it's agreed that it's a good idea, though, it would be interesting to discuss ways to support this code style in A-Frame to help component authors reduce garbage collection by default, without tripping over some of the existing optimizations under the hood in A-Frame.