Add BuilderElement and lang
This commit is contained in:
@ -3,14 +3,20 @@ import { IXmlableObject } from "./xmlable-object";
|
||||
|
||||
export type AttributeMap<T> = { readonly [P in keyof T]: string };
|
||||
|
||||
export type AttributeData = { readonly [key: string]: boolean | number | string };
|
||||
export type AttributePayload<T extends AttributeData> = Record<
|
||||
keyof T,
|
||||
{
|
||||
readonly key: string;
|
||||
readonly value?: T[keyof T];
|
||||
}
|
||||
>;
|
||||
|
||||
export abstract class XmlAttributeComponent<T extends object> extends BaseXmlComponent {
|
||||
// tslint:disable-next-line:readonly-keyword
|
||||
protected readonly root: T;
|
||||
protected readonly xmlKeys?: AttributeMap<T>;
|
||||
|
||||
public constructor(properties: T) {
|
||||
public constructor(private readonly root: T) {
|
||||
super("_attr");
|
||||
this.root = properties;
|
||||
}
|
||||
|
||||
public prepForXml(_: IContext): IXmlableObject {
|
||||
@ -26,3 +32,20 @@ export abstract class XmlAttributeComponent<T extends object> extends BaseXmlCom
|
||||
return { _attr: attrs };
|
||||
}
|
||||
}
|
||||
|
||||
export class NextAttributeComponent<T extends AttributeData> extends BaseXmlComponent {
|
||||
public constructor(private readonly root: AttributePayload<T>) {
|
||||
super("_attr");
|
||||
}
|
||||
|
||||
public prepForXml(_: IContext): IXmlableObject {
|
||||
const attrs = {};
|
||||
Object.values(this.root).forEach(({ key, value }) => {
|
||||
if (value !== undefined) {
|
||||
// eslint-disable-next-line functional/immutable-data
|
||||
attrs[key] = value;
|
||||
}
|
||||
});
|
||||
return { _attr: attrs };
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user