forked from requirejs/requirejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow define(string, function) where function should be scanned for d…
…ependencies. Test it by trying out some flavors of universal module boilerplate.
- Loading branch information
Showing
13 changed files
with
261 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
!function (name, definition) { | ||
if (typeof module != 'undefined') module.exports = definition() | ||
else if (typeof define == 'function' && typeof define.amd == 'object') define(name, definition) | ||
else this[name] = definition() | ||
}('eye', function() { | ||
return { | ||
name: 'eye' | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*jslint strict: false */ | ||
/*global define: false, module: false, require: false, window: false */ | ||
|
||
(function (define) { | ||
//The 'id' is optional, but recommended if this is | ||
//a popular web library that is used mostly in | ||
//non-AMD/Node environments. | ||
define(function (require) { | ||
//If have dependencies, get them here | ||
var tail = require('tail'), | ||
eye = require('eye'); | ||
|
||
//Return the module definition. | ||
return { | ||
name: 'newt', | ||
eyeName: eye.name, | ||
tailName: tail.name | ||
}; | ||
}); | ||
}(typeof define === 'function' && define.amd ? define : function (id, factory) { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
//Node | ||
module.exports = factory(require); | ||
} else { | ||
//Create a global function. Only works if | ||
//the code does not have dependencies, or | ||
//dependencies fit the call pattern below. | ||
window.myGlobal = factory(function (value) { | ||
return window[value]; | ||
}); | ||
} | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*jslint strict: false */ | ||
/*global define: false, module: false, require: false, window: false */ | ||
|
||
(function (define) { | ||
//The 'id' is optional, but recommended if this is | ||
//a popular web library that is used mostly in | ||
//non-AMD/Node environments. | ||
define('spell', function (require) { | ||
//If have dependencies, get them here | ||
var newt = require('newt'); | ||
|
||
//Return the module definition. | ||
return { | ||
name: 'spell', | ||
newtName: newt.name, | ||
tailName: newt.tailName, | ||
eyeName: newt.eyeName | ||
}; | ||
}); | ||
}(typeof define === 'function' && define.amd ? define : function (id, factory) { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
//Node | ||
module.exports = factory(require); | ||
} else { | ||
//Create a global function. Only works if | ||
//the code does not have dependencies, or | ||
//dependencies fit the call pattern below. | ||
window.myGlobal = factory(function (value) { | ||
return window[value]; | ||
}); | ||
} | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
!function (name, definition) { | ||
if (typeof module != 'undefined') module.exports = definition() | ||
else if (typeof define == 'function' && typeof define.amd == 'object') define('tail', definition) | ||
else this[name] = definition() | ||
}('tail', function() { | ||
return { | ||
name: 'tail' | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>require.js: Universal Module Wrapper: Built Tests</title> | ||
<script type="text/javascript" src="../doh/runner.js"></script> | ||
<script type="text/javascript" src="../doh/_browserRunner.js"></script> | ||
<script type="text/javascript" data-main="universal-tests-built" src="../../require.js"></script> | ||
</head> | ||
<body> | ||
<h1>require.js: Universal Module Wrapper: Built Tests</h1> | ||
<p>Check console for messages</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
|
||
!function (name, definition) { | ||
if (typeof module != 'undefined') module.exports = definition() | ||
else if (typeof define == 'function' && typeof define.amd == 'object') define('tail', definition) | ||
else this[name] = definition() | ||
}('tail', function() { | ||
return { | ||
name: 'tail' | ||
} | ||
}) | ||
; | ||
define("tail", function(){}); | ||
|
||
!function (name, definition) { | ||
if (typeof module != 'undefined') module.exports = definition() | ||
else if (typeof define == 'function' && typeof define.amd == 'object') define(name, definition) | ||
else this[name] = definition() | ||
}('eye', function() { | ||
return { | ||
name: 'eye' | ||
} | ||
}) | ||
; | ||
define("eye", function(){}); | ||
|
||
/*jslint strict: false */ | ||
/*global define: false, module: false, require: false, window: false */ | ||
|
||
(function (define) { | ||
//The 'id' is optional, but recommended if this is | ||
//a popular web library that is used mostly in | ||
//non-AMD/Node environments. | ||
define('newt',['require','tail','eye'],function (require) { | ||
//If have dependencies, get them here | ||
var tail = require('tail'), | ||
eye = require('eye'); | ||
|
||
//Return the module definition. | ||
return { | ||
name: 'newt', | ||
eyeName: eye.name, | ||
tailName: tail.name | ||
}; | ||
}); | ||
}(typeof define === 'function' && define.amd ? define : function (id, factory) { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
//Node | ||
module.exports = factory(require); | ||
} else { | ||
//Create a global function. Only works if | ||
//the code does not have dependencies, or | ||
//dependencies fit the call pattern below. | ||
window.myGlobal = factory(function (value) { | ||
return window[value]; | ||
}); | ||
} | ||
})); | ||
; | ||
/*jslint strict: false */ | ||
/*global define: false, module: false, require: false, window: false */ | ||
|
||
(function (define) { | ||
//The 'id' is optional, but recommended if this is | ||
//a popular web library that is used mostly in | ||
//non-AMD/Node environments. | ||
define('spell',['require','newt'], function (require) { | ||
//If have dependencies, get them here | ||
var newt = require('newt'); | ||
|
||
//Return the module definition. | ||
return { | ||
name: 'spell', | ||
newtName: newt.name, | ||
tailName: newt.tailName, | ||
eyeName: newt.eyeName | ||
}; | ||
}); | ||
}(typeof define === 'function' && define.amd ? define : function (id, factory) { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
//Node | ||
module.exports = factory(require); | ||
} else { | ||
//Create a global function. Only works if | ||
//the code does not have dependencies, or | ||
//dependencies fit the call pattern below. | ||
window.myGlobal = factory(function (value) { | ||
return window[value]; | ||
}); | ||
} | ||
})); | ||
; | ||
require({baseUrl: require.isBrowser ? "./" : "./universal/"}, ["spell"], function(spell) { | ||
doh.register( | ||
"universal", | ||
[ | ||
function universal(t){ | ||
t.is('spell', spell.name); | ||
t.is('newt', spell.newtName); | ||
t.is('tail', spell.tailName); | ||
t.is('eye', spell.eyeName); | ||
} | ||
] | ||
); | ||
|
||
doh.run(); | ||
}); | ||
; | ||
define("universal-tests", function(){}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require({baseUrl: require.isBrowser ? "./" : "./universal/"}, ["spell"], function(spell) { | ||
doh.register( | ||
"universal", | ||
[ | ||
function universal(t){ | ||
t.is('spell', spell.name); | ||
t.is('newt', spell.newtName); | ||
t.is('tail', spell.tailName); | ||
t.is('eye', spell.eyeName); | ||
} | ||
] | ||
); | ||
|
||
doh.run(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>require.js: Universal Module Wrapper Tests</title> | ||
<script type="text/javascript" src="../doh/runner.js"></script> | ||
<script type="text/javascript" src="../doh/_browserRunner.js"></script> | ||
<script type="text/javascript" data-main="universal-tests" src="../../require.js"></script> | ||
</head> | ||
<body> | ||
<h1>require.js: Universal Module Wrapper Tests</h1> | ||
<p>Check console for messages</p> | ||
</body> | ||
</html> |