Make all methods proxied for DAO
This commit is contained in:
parent
a953ba13de
commit
52d2c8425f
|
@ -503,7 +503,7 @@ DataSource.prototype.mixin = function (ModelCtor) {
|
||||||
var DAO = this.DataAccessObject;
|
var DAO = this.DataAccessObject;
|
||||||
|
|
||||||
// mixin DAO
|
// mixin DAO
|
||||||
jutil.mixin(ModelCtor, DAO);
|
jutil.mixin(ModelCtor, DAO, {proxyFunctions : true});
|
||||||
|
|
||||||
// decorate operations as alias functions
|
// decorate operations as alias functions
|
||||||
Object.keys(ops).forEach(function (name) {
|
Object.keys(ops).forEach(function (name) {
|
||||||
|
|
15
lib/jutil.js
15
lib/jutil.js
|
@ -42,14 +42,23 @@ exports.mixin = function (newClass, mixinClass, options) {
|
||||||
options = options || {
|
options = options || {
|
||||||
staticProperties: true,
|
staticProperties: true,
|
||||||
instanceProperties: 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) {
|
if (options.staticProperties) {
|
||||||
Object.keys(mixinClass).forEach(function (classProp) {
|
Object.keys(mixinClass).forEach(function (classProp) {
|
||||||
if (classProp !== 'super_' && classProp !== '_mixins' && (!newClass.hasOwnProperty(classProp) || options.override)) {
|
if (classProp !== 'super_' && classProp !== '_mixins' && (!newClass.hasOwnProperty(classProp) || options.override)) {
|
||||||
var pd = Object.getOwnPropertyDescriptor(mixinClass, classProp);
|
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);
|
pd.value = exports.proxy(pd.value);
|
||||||
}
|
}
|
||||||
Object.defineProperty(newClass, classProp, pd);
|
Object.defineProperty(newClass, classProp, pd);
|
||||||
|
@ -62,7 +71,7 @@ exports.mixin = function (newClass, mixinClass, options) {
|
||||||
Object.keys(mixinClass.prototype).forEach(function (instanceProp) {
|
Object.keys(mixinClass.prototype).forEach(function (instanceProp) {
|
||||||
if (!newClass.prototype.hasOwnProperty(instanceProp) || options.override) {
|
if (!newClass.prototype.hasOwnProperty(instanceProp) || options.override) {
|
||||||
var pd = Object.getOwnPropertyDescriptor(mixinClass.prototype, instanceProp);
|
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);
|
pd.value = exports.proxy(pd.value);
|
||||||
}
|
}
|
||||||
Object.defineProperty(newClass.prototype, instanceProp, pd);
|
Object.defineProperty(newClass.prototype, instanceProp, pd);
|
||||||
|
|
|
@ -686,9 +686,8 @@ describe('Injected remotable methods', function(){
|
||||||
M1.create.shared = false;
|
M1.create.shared = false;
|
||||||
assert.equal(M1.create.shared, false, 'M1.create should be local now');
|
assert.equal(M1.create.shared, false, 'M1.create should be local now');
|
||||||
assert.equal(M2.create.shared, true, 'M2.create should stay remotable');
|
assert.equal(M2.create.shared, true, 'M2.create should stay remotable');
|
||||||
// Non-shared method should be same
|
assert.notEqual(M1.prototype.save, M2.prototype.save,
|
||||||
assert.equal(M1.prototype.save, M2.prototype.save,
|
'non-remote methods are not shared');
|
||||||
'Local methods should be the same');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue