Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove() end early #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions src/Squire.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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.
*/
Expand Down Expand Up @@ -151,7 +151,7 @@ define(function() {
if (magicModuleLocation !== -1) {
dependencies.splice(magicModuleLocation, 1);
}

each(this.mocks, function(mock, path) {
define(path, mock);
});
Expand All @@ -173,7 +173,7 @@ define(function() {
}

callback.apply(null, args);

each(self.requiredCallbacks, function(cb) {
cb.call(null, dependencies, args);
});
Expand All @@ -200,15 +200,16 @@ 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];
};

Squire.prototype.run = function(deps, callback) {
var self = this;
var run = function(done) {
Expand All @@ -217,11 +218,11 @@ define(function() {
done();
});
};

run.toString = function() {
return callback.toString();
};

return run;
};

Expand Down