Skip to content
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

Iterable vectors #22548

Merged
merged 3 commits into from Sep 22, 2021
Merged

Iterable vectors #22548

merged 3 commits into from Sep 22, 2021

Conversation

ghost
Copy link

@ghost ghost commented Sep 17, 2021

Description

All vectors (Vector2, Vector3 and Vector4) are now iterable.

const vec = new THREE.Vector3(5,5.7,8);

Math.min(...vec.toArray());//before

Math.min(...vec);//after

Copy English documentation where applicable. Some languages did not
contain the math directory, which is where the English vector
documentation is located.
Copy link
Collaborator

@Mugen87 Mugen87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the browser support for this syntax is well enough to give it a try. Builds do work and our eslint setup has no problems with this code, too.

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 17, 2021

Out of curiosity: How does Babel process such generators? Is it possible to produce ES5 builds with this syntax?

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 17, 2021

That is an important topic since there are three.js users which require ES5. And since we use generators the first time in the core, we should clarify this question.

@ghost
Copy link
Author

ghost commented Sep 17, 2021

Hey, that is an important question, thanks for the inquiry. A plugin is required for it to work with ES5, it's called regenerator-runtime. I tested a class with a custom iterator and destructuring it worked as expected.

Edit: This plugin is also required by an official babel package. Babel-runtime

@donmccurdy
Copy link
Collaborator

It appears that regenerator-runtime and @babel/runtime are meant to be used as production dependencies of a library like three.js; they are not devDependencies like most of the Babel toolchain. Currently three.js has no production dependencies, so I think it may be better to wait for features like this until after IE11 end-of-life.

@looeee
Copy link
Collaborator

looeee commented Sep 20, 2021

it may be better to wait for features like this until after IE11 end-of-life.

Would adding this code break things for ES5 users even if they don't use it?

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 20, 2021

I would expect that IE11 is not able to parse JS code with generators. It would be a syntax error.

@mrdoob
Copy link
Owner

mrdoob commented Sep 20, 2021

I think at this point we no longer support IE11 but I do worry about bundlers. Do bundlers support this well?

@donmccurdy
Copy link
Collaborator

Browserify works fine with them, so I'd expect newer bundlers like Webpack, Parcel, and Rollup to be OK as well. They are an ES6 feature, so not actually all that new.

@mrdoob
Copy link
Owner

mrdoob commented Sep 22, 2021

Alright, lets see what happens 🤞

@mrdoob mrdoob added this to the r133 milestone Sep 22, 2021
@mrdoob mrdoob merged commit fbdb745 into mrdoob:dev Sep 22, 2021
@mrdoob
Copy link
Owner

mrdoob commented Sep 22, 2021

Thanks!

@0b5vr 0b5vr mentioned this pull request Oct 1, 2021
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants