@aire-ux/aire-condensation
Version:
Client-side serialization library for Aire-UX
49 lines (48 loc) • 1.4 kB
JavaScript
import "reflect-metadata";
import { Condensation } from "./condensation";
export class StringDeserializer {
read(object) {
return object;
}
}
export class BooleanDeserializer {
read(object) {
return object;
}
}
export class NumberDeserializer {
read(object) {
return object;
}
}
export class TypeRegistrationDeserializer {
constructor(type, registration) {
this.type = type;
this.registration = registration;
}
read(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);
}
}
bind(result, value) {
const reg = this.registration, props = reg.properties;
if (props) {
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);
}
}
return result;
}
}