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
Provenance
- Commit
33277c3- Tree
b4729e2- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
28f2ad0
8 files changed+13 added−99 removed
modified:lib/express/plugins/view.js+2 added-3 removed
3 unmodified lines4567898910111289 unmodified lines10210310410510710610710810911030 unmodified lines3 unmodified lines/** * Module dependencies. */
var utils = require('express/utils'), extname = require('path').extname,var extname = require('path').extname, fs = require('fs')
/** * Cache supported template engine exports.89 unmodified lines if (!partial) self.contentType(ext) function render(content) { content = (engines[type] = engines[type] || require(type)).render(content, options) if (layout) self.render(layout + '.' + type + ext, utils.mixin(true, options, { self.render(layout + '.' + type + ext, options.mergeDeep({ layout: false, locals: { body: content }30 unmodified linesmodified:lib/express/spec/mocks.js+3 added-6 removed
3 unmodified lines4 /**5 * Module dependencies.6 */7 8-var utils = require('express/utils'),9- path = require('path'),8+var path = require('path'),9 fs = require('fs')10 11 /**12 * Sync fs.readFile()56 unmodified lines69 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 })84 85 // --- MockResponse89 unmodified linesmodified:lib/express/http.js-1 removed
4 unmodified lines5 * Module dependencies.6 */7 8 var http = require('http'),9- utils = require('express/utils'),9 parse = require('url').parse,10 queryString = require('querystring')11 12 /**80 unmodified linesmodified:lib/express/plugin.js-18 removed
12345678910567819 unmodified lines28293031383940414243444546474849323334358 unmodified lines
// Express - Plugin - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
/** * Module dependencies. */
var utils = require('express/utils');
/** * Push _plugin_ with _options_ to the plugin stack. * If _plugin_ has already been pushed, then it's options * will override any previously set. *19 unmodified lines
exports.Plugin = new Class({ /** * Initialize with _options_. * * @param {hash} options * @api private */ constructor: function(options) { if (options) utils.mixin(this, options) }, /** * Trigger handler for the given _event_. * * @param {Event} event * @api private8 unmodified linesmodified:lib/express/request.js+7 added-9 removed
6 unmodified lines7 8 var statusBodies = require('http').STATUS_CODES,9 queryString = require('querystring'),10 mime = require('express/mime'),11- utils = require('express/utils'),11 url = require('url')12 13 // --- Helpers14 28 unmodified lines43 * @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 lines112 */113 114 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 linesmodified:lib/express/utils.js-61 removed
72 unmodified lines73 return parts[key]74 }, queryString.parseQuery(key))75 return orig76 }77-78-// 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)83-exports.mixin = function() {84- // copy reference to target object85- var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, source;86-87- // 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- }94-95- // Handle case when target is a string or something (possible in deep copy)96- if ( typeof target !== "object" && !(typeof target === 'function') )97- target = {};98-99- // mixin process itself if only one argument is passed100- if ( length == i ) {101- target = GLOBAL;102- --i;103- }104-105- 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) {120-121- 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 lines71 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