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

Update to use ES2015 syntax and modules #249

Merged
merged 10 commits into from
Jul 21, 2017
Merged

Update to use ES2015 syntax and modules #249

merged 10 commits into from
Jul 21, 2017

Conversation

toji
Copy link
Owner

@toji toji commented Jul 7, 2017

Pushing this as a pull request in case anyone wants to comment on it before I merge.

The modules conversion is based very heavily on the work done by @bjornharrtell in #209, so most credit goes his way! For the record I initially tried to do the conversion by using ES2015 classes with static methods. (So class vec3 { static create() { ... } }) but it turns out that the <vec>.length() functions screwed it up because the class types have a default, read only length attribute anyway. As a result I reverted back to Bjorn's original method of having each module be a collection of loose functions imported with import * as <type> from "path". I would have preferred the cleaner import <type> from "path" that the classes would have given us, but oh well. Maybe in a glMatrix v. 3.0 I'll rename the length function to get around it. ;)

Also took the opportunity to manually rebase pull requests #248, #247, #233 into this one to prevent forcing the authors to do that. Should also address #237, #240, #241 and does as much to mitigate #244 as I think this library is likely to do.

Apologies for the slowness of updates! I know there's a lot of other issues still open, and I'll try to get to them as I can, but this is a pretty tough project for me to sink a lot of time into these days. Between work and family I don't have nearly as much time as I used to to maintain personal projects like this one.

toji added 9 commits July 6, 2017 21:38
This commit doesn’t include an update to the modules system, nor does
it update the build system so build-min is broken for the moment.
Gets the min build working again, compiles for non-es2015 compatible
environments
Also switched modules from exporting classes full of static methods to
exporting collections of loose functions because <type>.length was
giving me way too many problems! (It’s apparently a default, readonly
property of all classes.)

In any case, we seem to be working everywhere now! All tests pass, and
built files work well in the browser. :)
Code by @mreinstein, I’ve just rebased it onto my modules changes.
Originally implemented by @jwu, I’ve just rebased it on top of the
modules change.
package.json Outdated
@@ -1,7 +1,7 @@
{
"name": "gl-matrix",
"description": "Javascript Matrix and Vector library for High Performance WebGL apps",
"version": "2.3.2",
"version": "2.4.0",
"main": "src/gl-matrix.js",
Copy link

Choose a reason for hiding this comment

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

I like the pattern of the "main" entry being the dist/ built file -- this lets others import via node or webpack/browserify still, but not need to assume any sort of ES support (and even if they use babel, they'd need to make sure that they have the same babel configs as you, although limited to the es2015 preset, less of an issue).

An importer would still need the same build environment as the project however if someone is only importing per module (gl-matrix/src/gl-matrix/mat3 vs gl-matrix), but that's the cost to them for selectively importing.

Any reason against using "main": "dist/gl-matrix.js",?

@toji
Copy link
Owner Author

toji commented Jul 8, 2017

I don't see why not. Thanks for pointing this out! I'll make the change in the next day or so.

@bjornharrtell
Copy link

I agree with "main": "dist/gl-matrix.js" but in addition the package.json could also have "module": "src/gl-matrix.js". This will allow tools that understand ES6 modules to use them. See https://github.com/rollup/rollup/wiki/pkg.module.

@mreinstein
Copy link
Contributor

@toji thanks for the update, much appreciated! Looks like some really great changes. A little sad to see browserify go. But webpack is still an improvement. 👍

this is a pretty tough project for me to sink a lot of time into these days.
Between work and family I don't have nearly as much time as I used to to
maintain personal projects like this one.

I'm wondering if the maintenance burden could be significantly eased for this project by pulling in all of the modules hosted on stackgl, which split these units out into individual modules? For example, https://www.npmjs.com/package/gl-vec3

Apologies if this has already come up and been decided against or is infeasible. Lately I've been lamenting that as great as the npm ecosystem is we have 164 different representatations for simple math contructs like vectors and matrices. stackgl/gl-mat3#1

@bjornharrtell
Copy link

bjornharrtell commented Jul 8, 2017

@mreinstein I think split/miniature packages are the unfortunate consequence of tools not able to pull in parts of a package which was indeed not possible before ES6 modules and that it actually increases maintenance burden. https://github.com/rollup/rollup showed that with proper use of ES6 modules there is no longer a need to split a library into multiple packages. AFAIK, webpack also supports this as of version 3 (see https://medium.com/webpack/webpack-3-official-release-15fd2dd8f07b).

@mreinstein
Copy link
Contributor

I think split/miniature packages are the unfortunate consequence of tools not able to
pull in parts of a package which was indeed not possible before ES6 modules

I wouldn't say it's unfortunate. :) But I'd like to avoid starting a flame war over tiny modules vs larger utility modules. Neither camp is right or wrong, it's just opinion. If you are in the camp of people that like small independent units that do less things, you could use the stackgl variants. If you want more of a fully contained vector/math grab bag, gl-matrix could potentially pull in all of those separate modules into 1 index file and make them available via es6. Both camps could get what they want, and it might reduce the maintenance burden on @toji because gl-matrix would hopefully just become a simple aggregator for all of those smaller modules.

@toji
Copy link
Owner Author

toji commented Jul 8, 2017

Updated "main" and "module" as suggested, thanks!

A little sad to see browserify go.

Technically browserify was never here. :) I tried it out because I had used a browserify-based workflow in some of my other code that uses modules, but there were some quirks about how it handled this project that I was less enthusiastic about. Fortunately webpack still does the trick with a dose of babel on the side.

I've been lamenting that as great as the npm ecosystem is we have 164 different representatations for simple math contructs like vectors and matrices.

I don't think I can do anything to actively help that. :) There will never be the "one true math lib" even if vector and matrix math become part of the JS core. Everyone has different needs. That's why I made glMatrix in the first place, because at the time nothing else suited my needs. Selfishly, that's why I'm making this update now, because I want to start using modules more consistently in my other code. The fact that y'all find this library useful too is just a bonus. 😉

@mreinstein
Copy link
Contributor

mreinstein commented Jul 8, 2017

There will never be the "one true math lib" even if vector and matrix math
become part of the JS core. Everyone has different needs.

@toji I think maybe there's some confusion; I'm not advocating for one true math lib. What I'm lamenting is that even within the subset of people that think gl-matrix is really great, There are multiple variants of just that project which have been forked, either because SIMD is unwanted, or because people want more specific modules with smaller scope. https://github.com/stackgl/gl-mat2, https://github.com/stackgl/gl-mat3, https://github.com/stackgl/gl-mat4, etc. These modules are being maintained by brilliant, experienced people (e.g., @mikolalysenko @hughsk and others) Right now those modules have to manually track the changes to gl-matrix to keep parity. You've expressed dissatisfaction with not having time to maintain this. I'm asking if we can come together and maintain this jointly. :)

lodash is a good example: it is a utility belt with a bunch of useful functions in it. If you want the full grab bag, you can just import lodash. Or if you want just debounce, you can npm install lodash.debounce and use that in your project without the other stuff.

Perhaps it's naive, but could gl-matrix just be a very simple one file module that imports all the independent modules?

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.

4 participants