From bf592413e12472bff295cc77cf474b0d7b7a790f Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 13 Dec 2013 16:45:31 -0800 Subject: [PATCH 1/2] Dedupe the alias methods during mixin To prevent the same method from showing up multiple times in API explorer, for example, Model.deleteById, Model.removeById --- lib/jutil.js | 22 +++++++++++++++++----- test/loopback-dl.test.js | 6 ++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/jutil.js b/lib/jutil.js index 6daa1134..33d81ea7 100644 --- a/lib/jutil.js +++ b/lib/jutil.js @@ -55,11 +55,12 @@ exports.mixin = function (newClass, mixinClass, options) { } if (options.staticProperties) { - Object.keys(mixinClass).forEach(function (classProp) { + var staticProxies = []; + Object.keys(mixinClass).forEach(function (classProp) { if (classProp !== 'super_' && classProp !== '_mixins' && (!newClass.hasOwnProperty(classProp) || options.override)) { var pd = Object.getOwnPropertyDescriptor(mixinClass, classProp); if(options.proxyFunctions && pd.writable && typeof pd.value === 'function') { - pd.value = exports.proxy(pd.value); + pd.value = exports.proxy(pd.value, staticProxies); } Object.defineProperty(newClass, classProp, pd); } @@ -68,11 +69,12 @@ exports.mixin = function (newClass, mixinClass, options) { if (options.instanceProperties) { if (mixinClass.prototype) { - Object.keys(mixinClass.prototype).forEach(function (instanceProp) { + var instanceProxies = []; + Object.keys(mixinClass.prototype).forEach(function (instanceProp) { if (!newClass.prototype.hasOwnProperty(instanceProp) || options.override) { var pd = Object.getOwnPropertyDescriptor(mixinClass.prototype, instanceProp); if(options.proxyFunctions && pd.writable && typeof pd.value === 'function') { - pd.value = exports.proxy(pd.value); + pd.value = exports.proxy(pd.value, instanceProxies); } Object.defineProperty(newClass.prototype, instanceProp, pd); } @@ -83,10 +85,20 @@ exports.mixin = function (newClass, mixinClass, options) { return newClass; }; -exports.proxy = function(fn) { +exports.proxy = function(fn, proxies) { + // Make sure same methods referenced by different properties have the same proxy + // For example, deleteById is an alias of removeById + proxies = proxies || []; + for(var i = 0; i Date: Sat, 14 Dec 2013 00:04:26 -0800 Subject: [PATCH 2/2] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e276cb1e..9f6772c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-datasource-juggler", - "version": "1.2.7", + "version": "1.2.9", "description": "LoopBack DataSoure Juggler", "keywords": [ "StrongLoop",