From fa5fa713f3344d947efb56c8106ceaa5a7e953a4 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 1 Oct 2013 11:43:51 -0400 Subject: [PATCH 1/2] end early from remove() method if we have no context --- src/Squire.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Squire.js b/src/Squire.js index 298f0e6..3dfb36e 100644 --- a/src/Squire.js +++ b/src/Squire.js @@ -200,10 +200,11 @@ define(function() { }; Squire.prototype.remove = function() { - var path; + var path, context = getContext(this.id); + if(!context) { return; } each(getContext(this.id).defined, function(dependency, path) { - undef(getContext(this.id), path); + undef(context, path); }, this); delete requirejs.s.contexts[this.id]; From df55a8df01ec3f51ff128c1254b9e1c8cb2c1ec3 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 1 Oct 2013 11:44:45 -0400 Subject: [PATCH 2/2] Remove trailing whitespace --- src/Squire.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Squire.js b/src/Squire.js index 3dfb36e..2439b77 100644 --- a/src/Squire.js +++ b/src/Squire.js @@ -1,32 +1,32 @@ define(function() { - + /** * Utility Functions */ - + var toString = Object.prototype.toString; - + var isArray = function(arr) { return toString.call(arr) === '[object Array]'; }; - + var indexOf = function(arr, search) { for (var i = 0, length = arr.length; i < length; i++) { if (arr[i] === search) { return i; } } - + return -1; }; - + var each = function(obj, iterator, context) { var breaker = {}; - + if (obj === null) { return; } - + if (Array.prototype.forEach && obj.forEach === Array.prototype.forEach) { obj.forEach(iterator, context); } else if (obj.length === +obj.length) { @@ -45,23 +45,23 @@ define(function() { } } }; - + /** * Require.js Abstractions */ - + var getContext = function(id) { return requirejs.s.contexts[id]; }; - + var undef = function(context, module) { if (context.undef) { return context.undef(module); } - + return context.require.undef(module); }; - + /** * Create a context name incrementor. */ @@ -151,7 +151,7 @@ define(function() { if (magicModuleLocation !== -1) { dependencies.splice(magicModuleLocation, 1); } - + each(this.mocks, function(mock, path) { define(path, mock); }); @@ -173,7 +173,7 @@ define(function() { } callback.apply(null, args); - + each(self.requiredCallbacks, function(cb) { cb.call(null, dependencies, args); }); @@ -202,14 +202,14 @@ define(function() { Squire.prototype.remove = function() { var path, context = getContext(this.id); if(!context) { return; } - + each(getContext(this.id).defined, function(dependency, path) { undef(context, path); }, this); - + delete requirejs.s.contexts[this.id]; }; - + Squire.prototype.run = function(deps, callback) { var self = this; var run = function(done) { @@ -218,11 +218,11 @@ define(function() { done(); }); }; - + run.toString = function() { return callback.toString(); }; - + return run; };