Permalink
Browse files

Fixes #71, allow defines with no callbacks.

Includes test and revs to 0.2.7
  • Loading branch information...
jrburke committed Nov 18, 2013
1 parent 1f9d667 commit abde6eb004c9ae6766704c66a70165154439bb0c
Showing with 51 additions and 5 deletions.
  1. +4 −4 almond.js
  2. +1 −1 package.json
  3. +1 −0 tests/all.js
  4. +15 −0 tests/defineNoCallback/defineNoCallback.html
  5. +30 −0 tests/defineNoCallback/defineNoCallback.js
View
@@ -1,5 +1,5 @@
/**
- * almond 0.2.6 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved.
+ * almond 0.2.7 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/almond for details
*/
@@ -259,14 +259,14 @@ var requirejs, require, define;
main = function (name, deps, callback, relName) {
var cjsModule, depName, ret, map, i,
args = [],
+ callbackType = typeof callback,
usingExports;
//Use name if no relName
relName = relName || name;
//Call the callback to define the module, if necessary.
- if (typeof callback === 'function') {
-
+ if (callbackType === 'undefined' || callbackType === 'function') {
//Pull out the defined dependencies and pass the ordered
//values to the callback.
//Default to [require, exports, module] if no deps
@@ -297,7 +297,7 @@ var requirejs, require, define;
}
}
- ret = callback.apply(defined[name], args);
+ ret = callback ? callback.apply(defined[name], args) : undefined;
if (name) {
//If setting exports via "module" is in play,
View
@@ -1,7 +1,7 @@
{
"name": "almond",
"description": "A minimal AMD API implementation for use in optimized browser builds.",
- "version": "0.2.6",
+ "version": "0.2.7",
"homepage": "http://github.com/jrburke/almond",
"author": "James Burke <jrburke@gmail.com> (http://github.com/jrburke)",
"repository": {
View
@@ -27,3 +27,4 @@ doh.registerUrl("hasOwnPropertyTests", "../hasOwnProperty/hasOwnProperty.html");
doh.registerUrl("firstDefine", "../firstDefine/firstDefine.html");
doh.registerUrl("topRelativeRequire", "../topRelativeRequire/topRelativeRequire.html");
doh.registerUrl("configDeps", "../configDeps/configDeps.html");
+doh.registerUrl("defineNoCallback", "../defineNoCallback/defineNoCallback.html");
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>almond: Define with No Callback Test</title>
+ <script type="text/javascript" src="../doh/runner.js"></script>
+ <script type="text/javascript" src="../doh/_browserRunner.js"></script>
+ <script type="text/javascript" src="../../almond.js"></script>
+ <script type="text/javascript" src="defineNoCallback.js"></script>
+</head>
+<body>
+ <h1>almond: Define with No Callback Test</h1>
+ <p>define() with no callback</p>
+ <p>Check console for messages</p>
+</body>
+</html>
@@ -0,0 +1,30 @@
+
+var obj = {};
+
+define('c', false);
+
+//Test undefined exports.
+define('a', function () {
+ obj.a = 'a';
+});
+
+define('b', ['c'], function(c) {
+ obj.b = 'b';
+ obj.c = c;
+});
+
+define('obj', ['a', 'b']);
+
+require(['obj'], function () {
+ doh.register(
+ 'defineNoCallback',
+ [
+ function defineNoCallback(t){
+ t.is('a', obj.a);
+ t.is('b', obj.b);
+ t.is(false, obj.c);
+ }
+ ]
+ );
+ doh.run();
+});

0 comments on commit abde6eb

Please sign in to comment.