Math: Make use of Static initialization blocks.#33140
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
Oh, this is nice. |
|
Seems like Webpack supports the class field + private fields since 5.36.0 (2021). |
|
I still hesitate, tbh^^. There is no ECMA 2022 feature that looks like a must have and I'm not sure it's worth to risk breakage for this type of refactoring. |
Support for import.meta.url syntax to improve KTX2 and DRACOLoader ergonomics is something I raise every once and awhile and dropping support for Webpack 4.x would enable. |
Do you remember how old was the Webpack that caused breakage last time? |
|
It was definitely Webpack 4.x. |
prototype.isMatrix2 = true) in constructors
|
5.x was first released back in 2020 and the last 4.x release was in September 2023, almost three years ago (v4.47.0). The last release before that (v4.46.0) was in November 2021. At this point (I'd argue far before) anyone who has refused to upgrade to Webpack 5 should not be surprised that it's breaking when updating some dependencies. Realistically that download number for 4.x will probably never be down as low as we'd like it to be to drop support but at some point we need to be able to make a decision that will enable us to be able use more modern Javascript features to improve both the usability of the project and our own development experience. |
|
Agreed. We need to keep moving. |
|
Okay, let's do it. Hopefully, it won't get too bumpy for users. To resolve the CI complains, we need to merge #33128 first which increases the ECMA version in the ESLint config. I'll reopen and merge the PR. |
|
@PoseidonEnergy Do you mind rebasing the PR so the new ESLint settings from #33128 are honored? |
1a69123 to
04dad3c
Compare
|
@Mugen87 Thanks, done |
prototype.isMatrix2 = true) in constructorsMost ThreeJS classes have a is* property on the prototype. This allows for typechecks without using instanceof. Recently the vector and matrix classes change to initialize this property using static initialization block. (PR here: mrdoob/three.js#33140) The types were updated to be 'static readonly isVector3: boolean' which means one can only access isVector3 like this: Vector3.isVector3 which is not useful. This commit reverts the type update and restores the previous functionality.
Most ThreeJS classes have a is* property on the prototype. This allows for typechecks without using instanceof. Recently the vector and matrix classes change to initialize this property using static initialization block. (PR here: mrdoob/three.js#33140) The types were updated to be 'static readonly isVector3: boolean' which means one can only access isVector3 like this: Vector3.isVector3 which is not useful. While the initialization of the property changed, the shape of the class did not. This commit reverts the type update and restores the previous functionality.
Most ThreeJS classes have a is* property on the prototype. This allows for typechecks without using instanceof. Recently the vector and matrix classes change to initialize this property using static initialization block. (PR here: mrdoob/three.js#33140) The types were updated to be 'static readonly isVector3: boolean' which means one can only access isVector3 like this: Vector3.isVector3 which is not useful. While the initialization of the property changed, the shape of the class did not. This commit reverts the type update and restores the previous functionality.
Description
Moves all of the
MatrixN.isMatrixN = trueandVectorN.isVectorN = trueassignments out of the constructors so they aren't unnecessarily re-set for every new instance.Side note: My IDE (WebStorm) is displaying an error for the
static { ... }block becauseecmaVersionin eslint.config.js is set to2018.ECMA 2022 Static Initialization Blocks probably should be supported in three.js: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks
@Mugen87 Related: #33128