Skip to content
Myr

Removed utils.mixin() use Object#mergeDeep()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

jQuery is messy, and this implementation is way to slow for SSJS, and just gross :)

authored by visionmedia · committed by visionmedia · parent 28f2ad0 · Browse files · 8 files+13 added−99 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+13 added−99 removed

  • tests:+4 added−7 removed
  • other:+9 added−92 removed

8 files+13 added−99 removed

modified:lib/express/plugins/view.js+2 added-3 removed
modified:lib/express/spec/mocks.js+3 added-6 removed
3 unmodified lines
4/**5 * Module dependencies.6 */7 8var utils = require('express/utils'),9 path = require('path'),8var path = require('path'),9 fs = require('fs')1011/**12 * Sync fs.readFile()
56 unmodified lines
69 70 constructor: function(method, path, options) {71 this.method = method72 this.url = path74 this.connection = {75 remoteAddress: '127.0.0.1'76 }73 this.connection = { remoteAddress: '127.0.0.1' }74 this.headers = {75 'host': 'localhost',76 'user-agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2 Safari/530.19',77 'accept': 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',78 'accept-language': 'en-us',79 'connection': 'keep-alive'80 }84 utils.mixin(true, this, options)81 this.mergeDeep(options)82 }83})8485// --- MockResponse
89 unmodified lines
modified:lib/express/http.js-1 removed
4 unmodified lines
5 * Module dependencies.6 */78var http = require('http'),9 utils = require('express/utils'),9 parse = require('url').parse,10 queryString = require('querystring')11 12/**
80 unmodified lines
modified:lib/express/plugin.js-18 removed
modified:lib/express/request.js+7 added-9 removed
6 unmodified lines
78var statusBodies = require('http').STATUS_CODES,9 queryString = require('querystring'),10 mime = require('express/mime'),11 utils = require('express/utils'),11 url = require('url')1213// --- Helpers14
28 unmodified lines
43 * @api private44 */45 46 constructor: function(request, response) {48 utils.mixin(this, request)47 this.merge(request)48 response.headers = {}49 this.response = response 50 this.url = url.parse(this.url)51 this.url.pathname = exports.normalizePath(this.url.pathname)
60 unmodified lines
112 */113114 accepts: function() {115 var accept = this.header('accept')117 return accept 118 ? arguments.any(function(path){119 var type = mime.type(path)120 return accept.indexOf(type) !== -1 ||121 accept.indexOf(type.split('/')[0]+'/*') !== -1122 })123 : true116 if (!accept) return true117 return arguments.any(function(path){118 var type = mime.type(path)119 return accept.indexOf(type) !== -1 ||120 accept.indexOf(type.split('/')[0] + '/*') !== -1121 })122 },123 124 /**125 * Check if the request was an xmlHttpRequest (ajax).
153 unmodified lines
modified:lib/express/utils.js-61 removed
72 unmodified lines
73 return parts[key]74 }, queryString.parseQuery(key))75 return orig76}7778// From jQuery.extend in the jQuery JavaScript Library v1.3.279// Copyright (c) 2009 John Resig80// Dual licensed under the MIT and GPL licenses.81// http://docs.jquery.com/License82// Modified for node.js (formely for copying properties correctly)83exports.mixin = function() {84 // copy reference to target object85 var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, source;8687 // Handle a deep copy situation88 if ( typeof target === "boolean" ) {89 deep = target;90 target = arguments[1] || {};91 // skip the boolean and the target92 i = 2;93 }9495 // Handle case when target is a string or something (possible in deep copy)96 if ( typeof target !== "object" && !(typeof target === 'function') )97 target = {};9899 // mixin process itself if only one argument is passed100 if ( length == i ) {101 target = GLOBAL;102 --i;103 }104105 for ( ; i < length; i++ ) {106 // Only deal with non-null/undefined values107 if ( (source = arguments[i]) != null ) {108 // Extend the base object109 Object.getOwnPropertyNames(source).forEach(function(k){110 var d = Object.getOwnPropertyDescriptor(source, k) || {value: source[k]};111 if (d.get) {112 target.__defineGetter__(k, d.get);113 if (d.set) {114 target.__defineSetter__(k, d.set);115 }116 }117 else {118 // Prevent never-ending loop119 if (target !== d.value) {120121 if (deep && d.value && typeof d.value === "object") {122 target[k] = exports.mixin(deep,123 // Never move original objects, clone them124 target[k] || (d.value.length != null ? [] : {})125 , d.value);126 }127 else {128 target[k] = d.value;129 }130 }131 }132 });133 }134 }135 // Return the modified object136 return target;137};
modified:lib/support/extnot shown

Its text is not shown, modified.

modified:spec/spec.request.js+1 added-1 removed
70 unmodified lines
71 72 describe 'when the Accept header is not present'73 it 'should return true'74 get('/user', function(){ return this.accepts('jpeg').toString() })75 get('/user', { headers: { accept: null }}).body.should.eql 'true'75 get('/user', { headers: { accept: '' }}).body.should.eql 'true'76 end77 end78 79 describe 'should allow multiple arguments'
168 unmodified lines