diff --git a/lib/datasource.js b/lib/datasource.js index 5cea8682..84adf376 100644 --- a/lib/datasource.js +++ b/lib/datasource.js @@ -503,7 +503,7 @@ DataSource.prototype.mixin = function (ModelCtor) { var DAO = this.DataAccessObject; // mixin DAO - jutil.mixin(ModelCtor, DAO); + jutil.mixin(ModelCtor, DAO, {proxyFunctions : true}); // decorate operations as alias functions Object.keys(ops).forEach(function (name) { diff --git a/lib/jutil.js b/lib/jutil.js index a74f254f..6daa1134 100644 --- a/lib/jutil.js +++ b/lib/jutil.js @@ -42,14 +42,23 @@ exports.mixin = function (newClass, mixinClass, options) { options = options || { staticProperties: true, instanceProperties: true, - override: false + override: false, + proxyFunctions: false }; + if(options.staticProperties === undefined) { + options.staticProperties = true; + } + + if(options.instanceProperties === undefined) { + options.instanceProperties = true; + } + if (options.staticProperties) { Object.keys(mixinClass).forEach(function (classProp) { if (classProp !== 'super_' && classProp !== '_mixins' && (!newClass.hasOwnProperty(classProp) || options.override)) { var pd = Object.getOwnPropertyDescriptor(mixinClass, classProp); - if(pd.writable && typeof pd.value === 'function' && pd.value.shared) { + if(options.proxyFunctions && pd.writable && typeof pd.value === 'function') { pd.value = exports.proxy(pd.value); } Object.defineProperty(newClass, classProp, pd); @@ -62,7 +71,7 @@ exports.mixin = function (newClass, mixinClass, options) { Object.keys(mixinClass.prototype).forEach(function (instanceProp) { if (!newClass.prototype.hasOwnProperty(instanceProp) || options.override) { var pd = Object.getOwnPropertyDescriptor(mixinClass.prototype, instanceProp); - if(pd.writable && typeof pd.value === 'function' && pd.value.shared) { + if(options.proxyFunctions && pd.writable && typeof pd.value === 'function') { pd.value = exports.proxy(pd.value); } Object.defineProperty(newClass.prototype, instanceProp, pd); diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index 4b50187d..62be6a4f 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -686,9 +686,8 @@ describe('Injected remotable methods', function(){ M1.create.shared = false; assert.equal(M1.create.shared, false, 'M1.create should be local now'); assert.equal(M2.create.shared, true, 'M2.create should stay remotable'); - // Non-shared method should be same - assert.equal(M1.prototype.save, M2.prototype.save, - 'Local methods should be the same'); + assert.notEqual(M1.prototype.save, M2.prototype.save, + 'non-remote methods are not shared'); });