-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
BoxGeometry: Introduce ES6 classes and ES6-ES5 conversion for builds. #17276
Conversation
I've also verified the performance difference of ES6 classes vs. a pure prototype style. Unlike articles from 2015/2016, it seems classes offer now an equal performance. |
👍 for going ahead with modernizing the code! I don't understand the purpose of the added closure. It looks like the exact same outcome can be achieved without it, and without polluting the global namespace or anything. This line puzzles me:
I did some testing with
If the above case is analogous, the first operand to Is ES6-ES5 conversion not possible with Babel, rather than Bublé? If it is, will the output code look different? |
@EliasHasle That code is transpiled by Bublé and shouldn't be intended to be looked at or edited by anyone I don't believe. Regarding using |
We could use Babel too, but Bublé does a much faster and simpler conversion. Although it's more limited than babel it should result in smaller file sizes since it doesn't add any helper functions to the code. As long as we're sticking with limited es6 features like classes it's probably better suited for use in a library like three.js. On the other hand babel is much more configurable so I'm sure it's possible to avoid adding helper functions there too and output a similar file size to Bublé. If you want to do some testing I'd be interested in seeing the results. But my gut feeling is that we'll end up deciding that Bublé is the best choice anyway. @Mugen87 perhaps you've already done some research here... What's your reason for choosing Bublé over Babel? |
It was actually recommended by @mrdoob 😇. I personally think if Bublé produces a sufficient outcome, I don't see the need for the more sophisticated Babel. I've tested some other ES6 features like default parameters with Bublé and everything works well. |
Yeah I agree. At least while we're just using a few easily transformed ES6 features, we don't need sophistication - and if we end up needing that later, or if someone demonstrates that Babel can be tweaked to output better or lighter code than Bublé, we can always switch. With that said, the following is included for anyone who wants to test Babel's output: Babel is now very simple to configure via @babel/preset-env and browser list.You just specify browsers that you want to target, and you can also tell it to skip adding polyfills and transforms with
If we do later find that we want to switch to this setup, it comes with the advantage that we can officially state which version of each browser we support, and provide a simple configuration script that can be modified if people want to rebuild to support older browsers or other environments. |
Sounds good! |
Will you eventually use/adapt https://github.com/Rich-Harris/convert-threejs-to-classes by @Rich-Harris, even though you closed #14654 in favor of this? |
Nope, I've planned to do it file by file and verify each class manually. It's a good opportunity to review the code in general. |
Lets do this! |
Thanks! |
Don't we use |
I guess we can start using them? |
Yeah, I think so unless it has any problems. |
The block scope provided by Presumably we are only using ES6 features in |
I guess block scope could also sometimes let JavaScript engine optimize the code better? In addition to |
I would focus on just moving to classes for now. We can investigate these other changes later. |
One step at a time.™ 😁 |
Agreed. Just in case, only in |
Yep. |
Off-topic about block-scoped variables
Also, the local scoping of the iteration counter lets you define callbacks in the loop using the value. Otherwise, you get multiple references to the function-scoped variable, and the traditional solution involves a horribly hard-to-grasp IIFE within the loop. |
@EliasHasle Please let's discuss such stuff in other issues at the right time. Classes now, other ES6 features later. |
OK. :-) |
I had a crappy week so far at work, but seeing this moving forward is making up for it! <3 well done |
Any chance you could investigate and see if we can get rid of that additional closure? I looked at Bublé options but I didn't figure it out. Maybe ask on Bublé`s repo? |
Done 👍: bublejs/buble#219 |
Thanks! |
Ah, I'd started writing a reply yesterday but got sidetracked — sorry. It went something like this:
Unfortunately Bublé isn't really maintained any more. We built it for an era when ES2015 was still the future, but other aspects of modern JavaScript that it doesn't accommodate (primarily Essentially, the only browser that doesn't support I'd advocate for leaving |
Oh, that's unfortunate...
That's kind of the plan. |
Moved to #15176. |
|
Please discuss this issue here: #15176 |
@Rich-Harris that seems to be the case with butternut as well. Do you think it would be a good idea to leave a note at the top of the readme for each repo warning people of this? It could save a lot of wasted dev hours. |
@looeee good idea — I've archived Butternut and opened an issue on Bublé to discuss (in case any of the other people who have contributed to it in the past intend to do so again in the future) |
@Rich-Harris I'd say it's probably a little premature to call the project unmaintained given it got 2 releases and several dozen commits in 2019 alone, and still powers software in production used by millions of people (such as Mapbox GL JS). I would wholeheartedly support deprecating any kind of transpilation in favor of shipping optimized ES module bundles if this were up to me alone; however, the truth is most of the enterprise world is stuck supporting IE11 for an undefined amount of time, it's a hard requirement from most of our big clients, so I will continue making sure Buble works for our needs in the nearest year at least. |
@mourner that's fair, I'll walk that back a bit. I meant more in the sense that it's not generally gaining new features, and I think it's only fair that projects be aware of that before adopting it. Very grateful for your commitment to the project! I guess my real point was that if we encourage library users to use modern ESM, it's not the worst thing in the world if people actively choosing to support IE11 need to pay a 1 or 2% transpilation tax. |
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.
See
All IIFEs are gone, so we can actually introduce ES6 classes in the code base. I've started with
BoxGeometry
as a first step.In order to ensure backwards compatibility, the PR introduces the usage of Bublé to perform a ES6 to ES5 conversion for
three.js
/three.min.js
. So users of these build files should not notice any difference.However, it is worth noting that
Bublé
will add an additional closure during the conversion process iff inheritance is used. The final code forBoxGeometry
looks like so:In any event, this approach enables the project to shift step by step to ES6 classes. In other words, it's not necessary to convert all files at once. It's possible to do this in batches (similar to the example modules) and verify each change for itself.
If this PR is going to be approved, I can take care about the others core files in the next time.