-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Src: Removed Object.defineProperty() calls. #21285
Conversation
@mrdoob do not despair! I am here to help. Just replace these lines three.js/test/unit/src/core/Object3D.tests.js Lines 300 to 304 in 1e210ac
with this assert.numEqual( obj.position.x, 1, 'x is equal' );
assert.numEqual( obj.position.y, 1.23, 'y is equal' );
assert.numEqual( obj.position.z, - 4.56, 'z is equal' ); And the tests are fixed. I tested this branch locally and there doesn't seem to be any other test that break. |
@marcofugaro thanks! |
It's still annoying that we can't just do |
I agree that's not optimal. I had thought that we'd be able to make use of static properties and methods. progress is slow. |
There is also doing: class Box2 {
isBox2 = true;
constructor( min, max ) {
this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
} i.e. moving items not dependent on constructor params outside of the constructor |
We should be aware that iterating with a
I wonder if the performance penalty mentioned in #21284 is not preferable compared to the change in behavior. Especially since the performance drop should not be visible if |
@marcofugaro Are you sure that I just did a test and it seems like it works just fine: f0ad404 I've also tried |
question mark? if tree-shaking is mostly surrounding I'd still prefer not to go back to either. I'd submit that keeping data related to an object inside of that object to be more beginner friendly than putting that same data somewhere within the file related to the object. don't mind me. I forgot this thing.was the a verdict regarding static properties yet?class Object3D {
static isObject3D = true
// ...
} Static properties are not a substitute for this because they are not accessible via the instance of that object |
Static properties are not a substitute for |
oops. I'd forgotten that discussion. |
I should google some things before askingquick question, why is `prototype` used? couldn't you just do `Vector3.isVector3 = true` ? |
I changed Vector2.js to: class Vector2 {
x;
y;
isVector2 = true;
constructor( x = 0, y = 0 ) {
this.x = x;
this.y = y;
} and this was preserved within the three.module.js but not within the three.js edit: var Vector2 = /*#__PURE__*/function () {
function Vector2(x, y) {
if (x === void 0) {
x = 0;
}
if (y === void 0) {
y = 0;
}
this.x = x;
this.y = y;
}
var _proto = Vector2.prototype;
_proto.isVector2 = true; within the three.js build |
It breaks it only for webpack but not rollup unfortunately π I added webpack to the script I took You can see it's present in the webpack bundle but not the rollup one:
I tested the webpack bundle before and after #21293 and it looks like the bundle size has gotten bigger:
I'd vote for #21293 to be reverted. In my opinion, doing |
Sorry, but I don't vote to do that. Like mentioned before the property iteration behavior is changed when doing this which can be very confusing and a breaking change for apps. |
Agreed. I vote for reporting this as a bug/feature request to Webpack. |
The Invites people to question why some classes have them but not others? And they should just not know about them |
Trivia: Rich Harris himself added them π€ |
TIL a quick way to test if a module tree-shakes: echo "import { Vector3 } from './src/math/Vector3.js'" | npx rollup -f es |
Done: webpack/webpack#12716 |
Fixes: #21284
Description
@marcofugaro but... as you said, this test will now fail?
And doingVector3.prototype.isVector3 = true
breaks tree shaking.π€·ββοΈ