From 515748a5dcb1f9772b83a157169a12d327c4590e Mon Sep 17 00:00:00 2001 From: Unchosen Date: Wed, 12 Jul 2017 22:39:07 +0800 Subject: [PATCH] Remove deepExtend mixin --- lib/core-client.js | 2 +- lib/proxy-communication.js | 2 +- lib/proxy-constructor.js | 4 ++-- lib/underscore-with-mixins.js | 21 +-------------------- tests/underscore-with-mixins.js | 17 ----------------- 5 files changed, 5 insertions(+), 41 deletions(-) diff --git a/lib/core-client.js b/lib/core-client.js index 1e33812..3646468 100644 --- a/lib/core-client.js +++ b/lib/core-client.js @@ -234,5 +234,5 @@ exports.preConfiguredProxy = (target, options)=>{ } } if (!proxyInterface || !client) throw Error("Target not found"); - return client.proxyCom.createProxy(_.deepExtend(_.deepExtend({}, proxyInterface.options), {preConfigure: options})); + return client.proxyCom.createProxy(_.extend(_.extend({}, proxyInterface.options), {preConfigure: _.extend({},options)})); }; diff --git a/lib/proxy-communication.js b/lib/proxy-communication.js index f74bb5e..9757bf0 100644 --- a/lib/proxy-communication.js +++ b/lib/proxy-communication.js @@ -118,7 +118,7 @@ const proxyCom = exports.proxyCom = class proxyCom { } createProxy(options = {}){ - return this.proxyConstructor.createProxyInterface(_.extend(_.deepExtend({}, options), { basePromise: this.clientConnectionToHostPromise })); + return this.proxyConstructor.createProxyInterface(_.extend(_.extend({}, options), { basePromise: this.clientConnectionToHostPromise })); } }; diff --git a/lib/proxy-constructor.js b/lib/proxy-constructor.js index aabb880..59fdb78 100644 --- a/lib/proxy-constructor.js +++ b/lib/proxy-constructor.js @@ -160,7 +160,7 @@ const proxyConstructor = exports.proxyConstructor = class proxyConstructor { if (!newOperator2) newOperator2 = _.isConstructed(this, proxyTargetConstructorResult); var proxyPromise = { constructorOptions, newOperator: newOperator2, property, args, argsActionID:0, proxyOptions: {}, timestamp: Date.now() }; if ('preConfigure' in proxyInterface.options && _.isObject(proxyInterface.options.preConfigure)) - _.deepExtend(proxyPromise.proxyOptions, proxyInterface.options.preConfigure); + _.extend(proxyPromise.proxyOptions, proxyInterface.options.preConfigure); proxyPromise.promise = new Promise((resolve2, reject2)=>{ var resolve = (...rArgs)=>{ self.endProxyPromise(proxyPromise, {resolve: true}); @@ -180,7 +180,7 @@ const proxyConstructor = exports.proxyConstructor = class proxyConstructor { }); proxyInterface.promiseMap.set(proxyPromise.promise, proxyPromise); proxyPromise.promise.configure = (...options)=>{ - if (options.length > 0) _.deepExtend(proxyPromise.proxyOptions, ...options); + if (options.length > 0) _.extend(proxyPromise.proxyOptions, ...options); return proxyPromise.promise; }; return proxyPromise.promise; diff --git a/lib/underscore-with-mixins.js b/lib/underscore-with-mixins.js index a4d97e9..a4b3a1f 100644 --- a/lib/underscore-with-mixins.js +++ b/lib/underscore-with-mixins.js @@ -26,27 +26,8 @@ const mixins = { isEventEmitter(obj) { let eventEmitter = mixins.isEventEmitter.eventEmitter = mixins.isEventEmitter.eventEmitter || require('events'); return (obj instanceof eventEmitter); - }, - - deepExtend(dest, ...source) { - for (var i = 0, l = source.length; i < l; i++) { - if (__.isArray(source[i])) - for (var j = 0, k = source[i].length; j < k; j++) { - var val = source[i][j]; - if (__.isArray(val)) dest.push(mixins.deepExtend([], val)); - else if (__.isObject(val)) dest.push(mixins.deepExtend({}, val)); - else dest.push(val); - } - else if (__.isObject(source[i])) - for (var key in source[i]) { - var val = source[i][key]; - if (__.isArray(val)) dest[key] = mixins.deepExtend([], val); - else if (__.isObject(val)) dest[key] = mixins.deepExtend({}, val); - else dest[key] = val; - } - } - return dest; } + }; // Do not use underscore's _.mixin; diff --git a/tests/underscore-with-mixins.js b/tests/underscore-with-mixins.js index 7790f1e..e452fc1 100644 --- a/tests/underscore-with-mixins.js +++ b/tests/underscore-with-mixins.js @@ -70,23 +70,6 @@ describe("Lib: underscore-with-mixins",()=>{ expect('test').to.not.satisfy(_.isStream.bind(_)); }); - it("mixin #deepExtend",()=>{ - expect(_).to.have.ownProperty('deepExtend'); - expect(_.deepExtend).to.be.a('function'); - var obj1 = { a:1, b:2, c:3, d:{ e:4 } }; - var obj2 = { foo:'bar', answer:42, sub:{ hello:'world' } }; - var testobj1 = _.extend({},obj1,obj2); - var testobj1str = JSON.stringify(testobj1); - var testobj2 = _.deepExtend({},obj1,obj2); - var testobj2str = JSON.stringify(testobj2); - expect(testobj1str).to.equal(testobj2str); - obj1.d.f = 5; - obj2.sub.hello = 'friend'; - //expect(JSON.stringify(testobj1)).to.not.equal(testobj1str); - expect(JSON.stringify(testobj2)).to.not.equal(JSON.stringify(testobj1)); - expect(JSON.stringify(testobj2)).to.equal(testobj2str); - }); - it("should have disabled methods",()=>{ expect(_.isFunction(_)).to.be.false; expect(_.mixin).to.throw(Error);