clear out clearVariables! In comes toXml

This commit is contained in:
felipe
2017-03-09 20:49:14 +01:00
parent 879b9163a3
commit 11e918114d
13 changed files with 26 additions and 141 deletions

View File

@ -1,5 +1,6 @@
import * as _ from "lodash";
import { BaseXmlComponent } from "./base";
export { BaseXmlComponent };
export abstract class XmlComponent extends BaseXmlComponent {
protected root: Array<BaseXmlComponent | string>;
@ -9,17 +10,15 @@ export abstract class XmlComponent extends BaseXmlComponent {
this.root = new Array<BaseXmlComponent>();
}
public replaceKey(): void {
// console.log(this.rootKey);
// console.log(this.root);
if (this.root !== undefined) {
this.root.forEach((root) => {
if (root && root instanceof BaseXmlComponent) {
root.replaceKey();
}
});
this[this.rootKey] = this.root;
delete this.root;
public toXml(): object {
const ret = this.root.map((comp) => {
if (comp instanceof BaseXmlComponent) {
return comp.toXml();
}
return comp
}).filter((comp) => comp); // Exclude null, undefined, and empty strings
return {
[this.rootKey]: ret,
}
}
}