Skip to content

Commit

Permalink
Removed Object#mixin()
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 22, 2010
1 parent 2cf3690 commit bbf6172
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 45 deletions.
2 changes: 1 addition & 1 deletion lib/connect/filters/session/memory.js
Expand Up @@ -33,7 +33,7 @@ var MemoryStore = exports.MemoryStore = function MemoryStore(options) {
this.maxAge = options.maxAge || 14400000;

// Cookie options
this.cookie = ({ path: '/', httpOnly: true }).mixin(options.cookie);
this.cookie = utils.merge({ path: '/', httpOnly: true }, options.cookie);

// Reap stale sessions
if (this.reapInterval !== -1) {
Expand Down
7 changes: 4 additions & 3 deletions lib/connect/index.js
Expand Up @@ -21,7 +21,8 @@ var sys = require('sys'),
http = require('http'),
Url = require('url'),
Path = require('path'),
assert = require('assert');
assert = require('assert')
utils = require('./utils');

// Response extensions

Expand All @@ -35,8 +36,8 @@ require('./response');
*/

function Layer(config) {
this.mixin(config);
this.mixin(config.module);
utils.merge(this, config);
utils.merge(this, config.module);

// Normalize routes
if (this.route[this.route.length - 1] !== '/') {
Expand Down
42 changes: 1 addition & 41 deletions lib/connect/proto.js
Expand Up @@ -35,44 +35,4 @@ if (typeof proto.forEach !== 'function') {
callback.call(thisObject, this[key], key, this);
}
}});
}

// Implements a map much like the one for Array.prototype.map, but for any
// object. Returns an array, not a generic object.
if (typeof proto.map !== 'function') {
Object.defineProperty(proto, "map", {value: function (callback, thisObject) {
var accum = [];
var keys = Object.keys(this);
var length = keys.length;
for (var i = 0; i < length; i++) {
var key = keys[i];
accum[i] = callback.call(thisObject, this[key], key, this);
}
return accum;
}});
}

// Implements a shallow copy onto the current object.
if (typeof proto.mixin !== 'function') {
Object.defineProperty(proto, "mixin", {value: function (obj) {
var keys = Object.keys(obj || {});
var length = keys.length;
for (var i = 0; i < length; i++) {
var key = keys[i];
this[key] = obj[key];
}
return this;
}});
}

// Implements a function curry function. This allows you to call part of a
// function later.
if (typeof func_proto.curry !== 'function') {
Object.defineProperty(func_proto, "curry", {value: function () {
var fn = this;
var first = arr_proto.slice.call(arguments);
return function () {
return fn.apply(this, first.concat(arr_proto.slice.call(arguments)));
};
}});
}
}
19 changes: 19 additions & 0 deletions lib/connect/utils.js
Expand Up @@ -46,6 +46,25 @@ exports.toBoolean = function(obj){
: !! obj;
};

/**
* Merge object b with object a.
*
* @param {Object} a
* @param {Object} b
* @return {Object}
* @api public
*/

exports.merge = function(a, b){
if (a && b) {
var keys = Object.keys(b);
for (var i = 0, len = keys.length; i < len; ++i) {
a[keys[i]] = b[keys[i]];
}
}
return a;
};

/**
* Parse mini markdown implementation.
* The following conversions are supported,
Expand Down

0 comments on commit bbf6172

Please sign in to comment.