Skip to content

Commit

Permalink
Remove collections dependency and es6-set instead
Browse files Browse the repository at this point in the history
Since [collections module][1] modifies native objects, it's only good
to be used as a top dependency of an application and not modules that
it's using.

The problem is that this will conflict if native objects has been
modified by another module, let's say something like [sugar][2] or just
another version of collections. When you have two of these being used in
your app, you might be in trouble, where some code depends on a
behaviour of a method implemented by one module but actually the method
had been silently overriden by another module having a different
behaviour.

[1]: http://collectionsjs.com
[2]: http://sugarjs.com
  • Loading branch information
faridnsh committed Jan 14, 2015
1 parent bd24d36 commit c58d9b5
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
5 changes: 2 additions & 3 deletions coverage-report.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

require("collections/shim");
var Q = require("q");
var FS = require("./fs");

Expand All @@ -22,7 +20,8 @@ FS.listTree(".coverage_data", function (name, stat) {
console.log(" </tr>");
console.log(" </thead>");
console.log(" <tbody>");
Object.forEach(coverage.files, function (file, path) {
Object.keys(coverage.files).forEach(function (path) {
var file = coverage.files[path];
path = FS.relativeFromDirectory(__dirname, path);
if (/^spec/.test(path))
return;
Expand Down
2 changes: 1 addition & 1 deletion fs-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Boot = require("./fs-boot");
var Common = require("./fs-common");
var BufferStream = require("./buffer-stream");
var Reader = require("./reader");
var Set = require("collections/set");
var Set = require("es6-set");

module.exports = MockFs;

Expand Down
1 change: 0 additions & 1 deletion http-apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
* @module
*/

require("collections/shim");
var Q = require("q");
var HTTP = require("./http");
var FS = require("./fs");
Expand Down
6 changes: 3 additions & 3 deletions http-apps/negotiate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ exports.Method = function (methods, methodNotAllowed) {
methodNotAllowed = Status.methodNotAllowed;
return function (request) {
var method = request.method;
if (Object.has(keys, method)) {
return Object.get(methods, method)(request);
if (keys.indexOf(method) !== -1) {
return methods[method](request);
} else {
return methodNotAllowed(request);
}
Expand All @@ -41,7 +41,7 @@ var Negotiator = function (requestHeader, responseHeader, respond) {
var type = MimeParse.bestMatch(keys, accept);
request.terms = request.terms || {};
request.terms[responseHeader] = type;
if (Object.has(keys, type)) {
if (keys.indexOf(type) !== -1) {
return Q.when(types[type](request), function (response) {
if (
respond !== null &&
Expand Down
4 changes: 2 additions & 2 deletions http-apps/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ exports.Branch = function (paths, notFound) {
var path = request.pathInfo.slice(1);
var parts = path.split("/");
var part = decodeURIComponent(parts.shift());
if (Object.has(paths, part)) {
if (hasOwnProperty.call(paths, part)) {
request.scriptName = request.scriptName + part + "/";
request.pathInfo = path.slice(part.length);
return Object.get(paths, part)(request, response);
return paths[part](request, response);
}
return notFound(request, response);
};
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"url": "http://github.com/kriskowal/q-io.git"
},
"dependencies": {
"q": "^1.0.1",
"qs": "^1.2.1",
"url2": "^0.0.0",
"es6-set": "^0.1.1",
"mime": "^1.2.11",
"mimeparse": "^0.1.4",
"collections": "^0.2.0"
"q": "^1.0.1",
"qs": "^1.2.1",
"url2": "^0.0.0"
},
"devDependencies": {
"jshint": "^0.9.1",
Expand Down

0 comments on commit c58d9b5

Please sign in to comment.