kevinroast/phoria.js — pull request #7 by veeenu (2014-03-15 10:04:57+00:00)
Title: AMD support refactoring

Introuced AMD compliance with backward compatibility.

Each class has been split in its own file and wrapped in a `define` call, each module has defined its own dependencies and some shimming has been done (namely: a definition of a `phoria-namespace` which is augmented by each module with its own dependencies; glMatrix has been wrapped in a `PhoriaGlMatrix` module with the augmentations made in phoria-util.js; each module using glMatrix has a bit of code that puts the `PhoriaGlMatrix` object's content in the local namespace so you can directly access objects like `vec3` and `mat4`) to preserve the original code.

Non-AMD scripts have been preserved, the refactoring is in the `amd/` directory.

A `Gruntfile.js` and a `package.json` file have been added. The former is the build script: simply run `grunt` and two new files will be created. These files are `scripts/phoria-amd.js` which contains the AMD-supporting library (which also puts `Phoria` in the `window` namespace) and `scripts/phoria-standalone.js` which can be loaded directly, in a backward-compatible way.

To enable minification of those two files, just change the value of the `optimize` key in the Gruntfile (lines 10, 22) from `none` to `uglify`.

The code hasn't been tested thoroughly for lack of time, but I included `test-amd.html` + `scripts/test-amd.js` and `test-amd-min.html` which have the behavior of `test0.html` and implement a use case of loading the AMD version and the standalone version of Phoria respectively.