removed reference to global 'define' with build

gets rid of the problem of having the global ‘define’ left defined in
the window which may have adverse effects on other AMD shim modules.
This commit is contained in:
Yotam Mann 2014-10-02 18:55:24 -04:00
parent 5ef854437a
commit 666d8f96c1
7 changed files with 33 additions and 42 deletions

View file

@ -5,37 +5,7 @@
*
* @license http://opensource.org/licenses/MIT MIT License 2014
*/
(function (root) {
// Tone.js can run with or without requirejs
//
// this anonymous function checks to see if the 'define'
// method exists, if it does not (and there is not already
// a function called Tone) it will create a function called
// 'define'. 'define' will invoke the 'core' module and attach
// its return value to the root. for all other modules
// Tone will be passed in as the argument.
if (typeof define !== "function" &&
typeof root.Tone !== "function") {
//define 'define' to invoke the callbacks with Tone
root.define = function(){
//the last argument is the callback
var lastArg = arguments[arguments.length - 1];
//the first argument is the dependencies or name
var firstArg = arguments[0];
if (firstArg === "Tone/core/Tone"){
//create the root object
root.Tone = lastArg();
} else if (typeof lastArg === "function"){
//if it's not the root, pass in the root
//as the parameter
lastArg(root.Tone);
}
};
}
} (this));
define("Tone/core/Tone", [], function(){
define(function(){
"use strict";

View file

@ -100,7 +100,7 @@ module.exports = function(grunt) {
},
wrap: {
dist: {
src: ["./Tone.js.tmp"],
src: ["../build/Tone.js"],
dest: "../build/Tone.js",
options: {
wrapper: [grunt.file.read("./fragments/before.frag"), grunt.file.read("./fragments/after.frag")]
@ -112,6 +112,13 @@ module.exports = function(grunt) {
options: {
wrapper: [grunt.file.read("./fragments/before.preset.frag"), grunt.file.read("./fragments/after.frag")]
}
},
min: {
src: ["../build/Tone.min.js"],
dest: "../build/Tone.min.js",
options: {
wrapper: [grunt.file.read("./fragments/before.frag.min"), grunt.file.read("./fragments/after.frag.min")]
}
}
},
indent: {
@ -148,9 +155,9 @@ module.exports = function(grunt) {
// Default task(s).
grunt.registerTask("docs", ["jsdoc:src"]);
grunt.registerTask("npm", ["copy:npm"]);
grunt.registerTask("presets", ["concat:presets"]);
grunt.registerTask("min", ["concat:dist", "requirejs:min", "concat:removeRequireStringMin", "clean:min"]);
grunt.registerTask("build", ["concat:dist","requirejs:compile","concat:removeRequireString", "clean:dist"]);
grunt.registerTask("presets", ["concat:presets", "wrap:presets"]);
grunt.registerTask("min", ["concat:dist", "requirejs:min", "concat:removeRequireStringMin", "clean:min", "wrap:min"]);
grunt.registerTask("build", ["concat:dist","requirejs:compile","concat:removeRequireString", "clean:dist", "wrap:dist"]);
grunt.registerTask("buildall", ["build", "min", "presets"]);
grunt.registerTask("dist", ["buildall", "docs", "npm"]);

View file

@ -1 +1,9 @@
} (this));
(function(root, undef) {
//leave no trace
//undefine 'define'
if (root.ToneDefinedDefine){
root.define = undef;
root.ToneDefinedDefine = undef;
}
}(this, undefined));

View file

@ -1 +1 @@
} (this));
void function(e,t){if(e.ToneDefinedDefine){e.define=t;e.ToneDefinedDefine=t}}(this,undefined)

View file

@ -10,7 +10,8 @@
if (typeof define !== "function" &&
typeof root.Tone !== "function") {
//define 'define' to invoke the callbacks with Tone
var define = function(){
root.ToneDefinedDefine = true;
root.define = function(){
//the last argument is the callback
var lastArg = arguments[arguments.length - 1];
//the first argument is the dependencies or name
@ -24,4 +25,5 @@
lastArg(root.Tone);
}
};
}
}
} (this));

View file

@ -1 +1 @@
(function(e){if(typeof define!=="function"&&typeof e.Tone!=="function"){e.define=function(){var t=arguments[arguments.length-1];var n=arguments[0];if(n==="Tone/core/Tone"){e.Tone=t()}else if(typeof t==="function"){t(e.Tone)}}}})(this)
(function(e){if(typeof define!=="function"&&typeof e.Tone!=="function"){e.ToneDefinedDefine=true;e.define=function(){var t=arguments[arguments.length-1];var n=arguments[0];if(n==="Tone/core/Tone"){e.Tone=t()}else if(typeof t==="function"){t(e.Tone)}}}})(this)

View file

@ -1,8 +1,10 @@
(function (root) {
//AMD shim for the presets build
if (typeof define !== "function" &&
typeof root.Tone === "function") {
//define 'define' to invoke the callbacks with Tone
var define = function(){
root.ToneDefinedDefine = true;
root.define = function(){
//the last argument is the callback
var lastArg = arguments[arguments.length - 1];
//the first argument is the dependencies or name
@ -12,4 +14,6 @@
lastArg(root.Tone);
}
};
}
}
} (this));