UNPKG

vox-core

Version:

Runtime de aplicaciones multiplataforma

142 lines (127 loc) 3.39 kB
var consts=core.org.voxsoftware.Lpr.Constants; /** * Clase que representa un Field de una clase u objeto .NET * @memberof org.voxsoftware.Lpr * @constructor * @param {Object} options * @protected */ var Field= module.exports= function(args){ if(args.static){ this.typename= args.typename; this.static=true; } this.native= false; this.type= args.type; this.manager= this.type.manager; this.name= args.name; this.index= args.index; } /** * Obtener una función para ajustar el valor del Field que representa * <br>Esta función es llamada automáticamente al ejecutar * {@link org.voxsoftware.Lpr.Type.Field} o {@link org.voxsoftware.Lpr.Type.StaticField} * y su valor se coloca como un método con el prefijo `set` y el nombre * del Field dentro del objeto si es estático o del prototipo * si es de instancia * @return {Function} * @example * LprType.staticField('AnyField') // Carga el Field en el tipo * var field= LprType.m.AnyField * var task= field.set()(newvalue); * task.then(function(){ * //OK * }, function(er){ * // Error * }) * @example * LprType.staticField('AnyField') // Carga el Field en el tipo * var task= LprType.setAnyField(newvalue); * task.then(function(){ * //OK * }, function(er){ * // Error * }) */ Field.prototype.set= function(){ var self= this; var f= function(){ var value=arguments[0]; return self.invoke(this, value, !!this.native); } return f; } /** * Obtener una función para obtener el valor del Field que representa * <br>Esta función es llamada automáticamente al ejecutar * {@link VW.Clr.Type.Field} o {@link VW.Clr.Type.StaticField} * y su valor se coloca como un método con el prefijo `get` y el nombre * del Field dentro del objeto si es estático o del prototipo * si es de instancia * @return {Function} * @example * var field= ClrType.m.AnyField * var task= field.get()(); * task.then(function(value){ * //OK * console.log(value) * }, function(er){ * // Error * }) */ Field.prototype.get= function(){ var self= this; var f= function(){ return self.invoke(this, undefined, !!this.native); } return f; } /** * Este método es más utilizado de manera interna por vox-core * <br>Permite realizar un ajuste o una obtención del Field (get o set) * <br>Este método es asíncrono * @param {VW.Clr.Type} obj * @param {Mixed} [value] Si se manda este valor diferente a `undefined` significa que hace un `set` * @param {Boolean} [native] Si es `true`, el resultado es convertido a un objeto JavaScript plano o a su valor primitivo * @return {VW.Task} Tarea asíncrona. Al finalizar devuelve el resultado del `get` o `set` del Field */ Field.prototype.invoke= function(obj,value, native){ var ipc= this.manager.ipc; var id= (++ipc.commandid); var opt={}; if(this.static){ opt.typename= this.typename; }else{ opt.objectid=obj.CSid; } if(this.index) opt.nameindex= this.index+1 else opt.name=this.name; opt.commandid= id; if(value!==undefined){ opt.value= ipc.processArg(value); opt.c= consts.SetField; } else{ opt.c= consts.GetField; } if(native){ opt.command="get"; } ipc.setObject(obj,id); var task= ipc.send(opt); var scope= obj?obj.scope:this.type.scope if(scope){ this.type.scope=null task.beforeExpose(function(){ if(task.result){ if(task.result.CSid){ scope.include(task.result) task.result.scope=scope } } }) } return task }