@aire-ux/aire-condensation
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -36,3 +36,3 @@ import TypeRegistry from "./type-registry"; | ||
create(t, ...args) { | ||
const actualParams = this.formalParams(t, "constructor", ...args); | ||
const actualParams = this.formalParams(t, "constructor", 'constructor', ...args); | ||
return allocate(new t(...actualParams), this.region); | ||
@@ -51,3 +51,3 @@ } | ||
} | ||
const formals = this.formalParams(Object.getPrototypeOf(value).constructor, "method", ...args); | ||
const formals = this.formalParams(Object.getPrototypeOf(value).constructor, "method", op, ...args); | ||
return operation.apply(value, formals); | ||
@@ -70,3 +70,3 @@ } | ||
} | ||
const formals = this.formalParams(Object.getPrototypeOf(v).constructor, "method", ...args); | ||
const formals = this.formalParams(Object.getPrototypeOf(v).constructor, "method", op, ...args); | ||
return operation.apply(v, formals); | ||
@@ -81,4 +81,5 @@ } | ||
} | ||
formalParams(t, type, ...args) { | ||
const remotes = Condensation.remoteRegistry, remote = remotes.resolve(t), ctorArgs = remote.definitions.filter((definition) => definition.invocationType === type); | ||
formalParams(t, type, operation, ...args) { | ||
const remotes = Condensation.remoteRegistry, remote = remotes.resolve(t), ctorArgs = remote.definitions.filter((definition) => definition.invocationType === type | ||
&& definition.invocationTarget == operation); | ||
if (ctorArgs.length !== args.length) { | ||
@@ -85,0 +86,0 @@ throw new Error(`Error: ${type} argument count mismatch. Expected ${ctorArgs.length}, got ${args.length}`); |
@@ -24,5 +24,15 @@ import "reflect-metadata"; | ||
read(value) { | ||
// const result = this.type.call(null); | ||
const result = new this.type(); | ||
return this.bind(result, value); | ||
if (Array.isArray(value)) { | ||
const values = value, result = []; | ||
for (const v of values) { | ||
const read = new this.type(); | ||
result.push(this.bind(read, v)); | ||
} | ||
return result; | ||
} | ||
else { | ||
// const result = this.type.call(null); | ||
const result = new this.type(); | ||
return this.bind(result, value); | ||
} | ||
} | ||
@@ -32,14 +42,6 @@ bind(result, value) { | ||
if (props) { | ||
if (Array.isArray(value)) { | ||
for (let [key, v] of props) { | ||
const readAlias = v.readAlias, deserializer = Condensation.deserializerFor(v.type), values = value, pvals = values.map((val) => deserializer.read(val)); | ||
Reflect.set(result, v.realName, pvals, result); | ||
} | ||
for (let [key, v] of props) { | ||
const readAlias = v.readAlias, deserializer = Condensation.deserializerFor(v.type), subobject = value[readAlias], propertyValue = deserializer.read(subobject); | ||
Reflect.set(result, v.realName, propertyValue, result); | ||
} | ||
else { | ||
for (let [key, v] of props) { | ||
const readAlias = v.readAlias, deserializer = Condensation.deserializerFor(v.type), subobject = value[readAlias], propertyValue = deserializer.read(subobject); | ||
Reflect.set(result, v.realName, propertyValue, result); | ||
} | ||
} | ||
} | ||
@@ -46,0 +48,0 @@ return result; |
@@ -30,3 +30,3 @@ import { Condensation } from "./condensation"; | ||
descriptor.value = function (...args) { | ||
const formals = ctx.formalParams(target.constructor, 'method', ...args); | ||
const formals = ctx.formalParams(target.constructor, 'method', propertyKey, ...args); | ||
return original.apply(this, formals); | ||
@@ -33,0 +33,0 @@ // return original.bind(target).apply(target, ...formals); |
{ | ||
"name": "@aire-ux/aire-condensation", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Client-side serialization library for Aire-UX", | ||
@@ -81,3 +81,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "4626c9ac00cd24cf7f7e7c8767acc7c4508336a7" | ||
"gitHead": "b4dd0240aa16e8a611b8544281b0a80cacf173b9" | ||
} |
@@ -94,3 +94,3 @@ import TypeRegistry from "@condensation/type-registry"; | ||
create<T>(t: Class<T>, ...args: string[]): Pointer<T> { | ||
const actualParams = this.formalParams(t, "constructor", ...args); | ||
const actualParams = this.formalParams(t, "constructor", 'constructor', ...args); | ||
return allocate(new t(...actualParams) as T, this.region); | ||
@@ -115,2 +115,3 @@ } | ||
"method", | ||
op, | ||
...args | ||
@@ -144,2 +145,3 @@ ); | ||
"method", | ||
op, | ||
...args | ||
@@ -162,2 +164,3 @@ ); | ||
type: InvocationType, | ||
operation: string, | ||
...args: string[] | ||
@@ -168,3 +171,5 @@ ): any[] { | ||
ctorArgs = remote.definitions.filter( | ||
(definition) => definition.invocationType === type | ||
(definition) => | ||
definition.invocationType === type | ||
&& definition.invocationTarget == operation | ||
); | ||
@@ -171,0 +176,0 @@ if (ctorArgs.length !== args.length) { |
import "reflect-metadata"; | ||
import { Class } from "@condensation/types"; | ||
import { TypeRegistration } from "@condensation/type-registry"; | ||
import { Condensation } from "@condensation/condensation"; | ||
import {Class} from "@condensation/types"; | ||
import {TypeRegistration} from "@condensation/type-registry"; | ||
import {Condensation} from "@condensation/condensation"; | ||
@@ -27,12 +27,24 @@ export interface Deserializer<T> { | ||
} | ||
export class TypeRegistrationDeserializer<T> implements Deserializer<T> { | ||
constructor( | ||
readonly type: Class<T>, | ||
readonly registration: TypeRegistration<T> | ||
) {} | ||
readonly type: Class<T>, | ||
readonly registration: TypeRegistration<T> | ||
) { | ||
} | ||
read(value: any): T { | ||
// const result = this.type.call(null); | ||
const result = new this.type(); | ||
return this.bind(result, value); | ||
if(Array.isArray(value)) { | ||
const values = value as any[], | ||
result = []; | ||
for(const v of values) { | ||
const read = new this.type(); | ||
result.push(this.bind(read, v)); | ||
} | ||
return result as any as T; | ||
} else { | ||
// const result = this.type.call(null); | ||
const result = new this.type(); | ||
return this.bind(result, value); | ||
} | ||
} | ||
@@ -42,20 +54,10 @@ | ||
const reg = this.registration, | ||
props = reg.properties; | ||
props = reg.properties; | ||
if (props) { | ||
if (Array.isArray(value)) { | ||
for (let [key, v] of props) { | ||
const readAlias = v.readAlias, | ||
for (let [key, v] of props) { | ||
const readAlias = v.readAlias, | ||
deserializer = Condensation.deserializerFor(v.type), | ||
values = value as any, | ||
pvals = values.map((val: any) => deserializer.read(val)); | ||
Reflect.set(result as any, v.realName, pvals, result); | ||
} | ||
} else { | ||
for (let [key, v] of props) { | ||
const readAlias = v.readAlias, | ||
deserializer = Condensation.deserializerFor(v.type), | ||
subobject = (value as any)[readAlias], | ||
propertyValue = deserializer.read(subobject); | ||
Reflect.set(result as any, v.realName, propertyValue, result); | ||
} | ||
Reflect.set(result as any, v.realName, propertyValue, result); | ||
} | ||
@@ -62,0 +64,0 @@ } |
@@ -40,3 +40,3 @@ import {Class} from "@condensation/types"; | ||
descriptor.value = function(...args: any[]) { | ||
const formals = ctx.formalParams(target.constructor, 'method', ...args); | ||
const formals = ctx.formalParams(target.constructor, 'method', propertyKey, ...args); | ||
return original.apply(this, formals); | ||
@@ -43,0 +43,0 @@ // return original.bind(target).apply(target, ...formals); |
@@ -324,2 +324,74 @@ import {Receive, Remotable, Remote} from "@condensation/remotable"; | ||
expect(vertex.label).toBe("hello"); | ||
}); | ||
test('add all should work', () => { | ||
@RootElement | ||
class Vertex { | ||
@Property(Number) | ||
private x: number | undefined; | ||
@Property(Number) | ||
private y: number | undefined; | ||
@Property(Number) | ||
private width: number | undefined; | ||
@Property(Number) | ||
private height : number | undefined; | ||
@Property(String) | ||
label: string | undefined; | ||
} | ||
@Remotable | ||
@customElement('aire-canvas2') | ||
class Canvas extends LitElement { | ||
readonly vertices: Vertex[]; | ||
constructor() { | ||
super(); | ||
this.vertices = []; | ||
} | ||
@Remote | ||
public addVertex(@Receive(Vertex) vertex: Vertex) { | ||
this.vertices.push(vertex); | ||
// this.graph?.addNode(vertex as any); | ||
} | ||
@Remote | ||
public addVertices(@Receive(Vertex) vertex: Vertex[]) { | ||
this.vertices.push(...vertex); | ||
// this.graph?.addNode(vertex as any); | ||
} | ||
} | ||
const canvas = new Canvas(); | ||
expect(canvas.vertices).toBeTruthy(); | ||
// @ts-ignore | ||
canvas.addVertices(` | ||
[{ | ||
"x": null, | ||
"y": null, | ||
"label": "hello", | ||
"width": null, | ||
"height": null | ||
}, | ||
{ | ||
"x": null, | ||
"y": null, | ||
"label": "jello", | ||
"width": null, | ||
"height": null | ||
}] | ||
`); | ||
expect(canvas.vertices.length).toBe(2); | ||
let vertex = canvas.vertices[0]; | ||
expect(vertex.label).toBe("hello"); | ||
vertex = canvas.vertices[1]; | ||
expect(vertex.label).toBe("jello"); | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109854
3058