2017-03-08 21:49:41 +00:00
|
|
|
import { BaseXmlComponent } from "./base";
|
2016-05-20 00:40:31 +01:00
|
|
|
|
2017-07-07 14:31:08 +01:00
|
|
|
export type AttributeMap<T> = {[P in keyof T]: string};
|
2016-05-20 00:40:31 +01:00
|
|
|
|
2017-03-10 10:42:24 +01:00
|
|
|
export abstract class XmlAttributeComponent<T> extends BaseXmlComponent {
|
|
|
|
protected root: T;
|
|
|
|
protected xmlKeys: AttributeMap<T>;
|
2016-05-20 00:40:31 +01:00
|
|
|
|
2017-03-10 10:42:24 +01:00
|
|
|
constructor(properties: T) {
|
|
|
|
super("_attr");
|
2016-05-26 15:08:34 +01:00
|
|
|
this.root = properties;
|
2016-05-20 00:40:31 +01:00
|
|
|
}
|
|
|
|
|
2017-04-15 20:11:54 +01:00
|
|
|
public prepForXml(): XmlableObject {
|
2017-03-09 20:49:14 +01:00
|
|
|
const attrs = {};
|
2017-03-10 10:42:24 +01:00
|
|
|
Object.keys(this.root).forEach((key) => {
|
|
|
|
const value = this.root[key];
|
|
|
|
if (value !== undefined) {
|
|
|
|
const newKey = this.xmlKeys[key];
|
|
|
|
attrs[newKey] = value;
|
|
|
|
}
|
|
|
|
});
|
2017-03-10 08:58:29 +01:00
|
|
|
return {_attr: attrs};
|
2016-05-20 00:40:31 +01:00
|
|
|
}
|
2017-03-08 21:49:41 +00:00
|
|
|
}
|