UNPKG

vox-core

Version:

Runtime de aplicaciones multiplataforma

155 lines (139 loc) 3.94 kB
var consts= core.org.voxsoftware.Lpr.Constants; /** * Clase que representa una propiedad estática o de instancia .NET * @memberof VW.Clr * @constructor * @param {Object} options * @protected */ var Property= 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 Property que representa * <br>Esta función es llamada automáticamente al ejecutar * {@link VW.Clr.Type.property} o {@link VW.Clr.Type.staticProperty} * y su valor se coloca como un método con el prefijo `set` y el nombre * del Property dentro del objeto si es estático o del prototipo * si es de instancia * @return {Function} * @example * ClrType.staticProperty('AnyProperty') // Carga el Property en el tipo * var prop= ClrType.m.AnyProperty * var task= prop.set()(newvalue); * task.then(function(){ * //OK * }, function(er){ * // Error * }) * @example * ClrType.staticProperty('AnyProperty') // Carga el Property en el tipo * var task= ClrType.setAnyProperty(newvalue); * task.then(function(){ * //OK * }, function(er){ * // Error * }) */ Property.prototype.set= function(){ var self= this; var f= function(){ var args= Array.prototype.slice.call(arguments,1,arguments.length); var value=arguments[0]; var native= self.nativeJS!==undefined?self.nativeJS:!!this.native return self.invoke(this, value, args, native); } return f; } /** * Obtener una función para obtener el valor del Property que representa * <br>Esta función es llamada automáticamente al ejecutar * {@link VW.Clr.Type.property} o {@link VW.Clr.Type.staticProperty} * y su valor se coloca como un método con el prefijo `get` y el nombre * del Property dentro del objeto si es estático o del prototipo * si es de instancia * @return {Function} * @example * ClrType.staticProperty('AnyProperty') // Carga el Property en el tipo * var prop= ClrType.m.AnyProperty * var task= prop.get()(); * task.then(function(value){ * //OK * }, function(er){ * // Error * }) * @example * ClrType.staticProperty('AnyProperty') // Carga el Property en el tipo * var task= ClrType.getAnyProperty(); * task.then(function(){ * //OK * }, function(er){ * // Error * }) */ Property.prototype.get= function(){ var self= this; var f= function(){ return self.invoke(this, undefined, arguments, !!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 Property (get o set) * <br>Este método es asíncrono * @param {VW.Clr.Type} obj `null` si es estático * @param {Mixed} [value] Si se manda este valor diferente a `undefined` significa que hace un `set` * @param {Array} [args] Esta argumento se debe especificar si la propiedad acepta índices * @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. Retorna el valor del Property */ Property.prototype.invoke= function(obj,value, args, 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.arguments= ipc.processArgs(args); opt.commandid= id; if(value!==undefined){ opt.value= ipc.processArg(value); opt.c= consts.SetProperty; } else{ opt.c= consts.GetProperty; } 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 }