Skip to content

Commit

Permalink
array list added
Browse files Browse the repository at this point in the history
  • Loading branch information
mkashifse committed Mar 20, 2019
1 parent d8042ae commit 4c22ebf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/auto-serialize.deco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export function AutoSerialize<T extends { new(...args: any[]): {} }>(constructor
const keys = (<any>parent)['__KEYS__'];
if (keys) {
keys.forEach((item: any) => {
(<any>this)[item.key] = new item.type().setValues(values[item.key]);
if (item.type.length) {
(<any>this)[item.key] = values[item.key].map((li: any) => new item.type[0]().setValues(li))
} else {
(<any>this)[item.key] = new item.type().setValues(values[item.key]);
}
});
}
return this;
Expand Down
23 changes: 17 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class Todo extends AbstractSerialize {
id: number = null;
text: string = 'First';
desc: string = 'first todo description';
list: string[] = ['abc', 'ssc', 'sds'];
@MapTo(Address) address: Address = new Address();
@MapTo([Address]) list: Address[] = [];

constructor() {
super();
Expand All @@ -39,10 +39,21 @@ export class Todo extends AbstractSerialize {
}

const todo = new Todo().setValues({
text: 'again', address: {
house:'new house',
street:'new street',
}
text: 'again',
address: {
house: 'new house',
street: 'new street',
},
list: [
{
house: 'new house',
street: 'new street',
},
{
house: 'new house',
street: 'new street',
},
]
}) as Todo;

console.log(todo.address.fullAddress());
console.log(todo.getValues());

0 comments on commit 4c22ebf

Please sign in to comment.