Introduce some functional programming techniques

This commit is contained in:
Dolan
2018-11-02 02:51:57 +00:00
parent 9cfd835171
commit 7980f14efb
108 changed files with 749 additions and 659 deletions

View File

@ -1,29 +1,29 @@
import { XmlAttributeComponent } from "./default-attributes";
export interface IAttributesProperties {
val?: string | number | boolean;
color?: string;
space?: string;
sz?: string;
type?: string;
rsidR?: string;
rsidRPr?: string;
rsidSect?: string;
w?: string;
h?: string;
top?: string;
right?: string;
bottom?: string;
left?: string;
header?: string;
footer?: string;
gutter?: string;
linePitch?: string;
pos?: string | number; // Little strange. Perhaps it is normal. Need to clarify in the spec.
readonly val?: string | number | boolean;
readonly color?: string;
readonly space?: string;
readonly sz?: string;
readonly type?: string;
readonly rsidR?: string;
readonly rsidRPr?: string;
readonly rsidSect?: string;
readonly w?: string;
readonly h?: string;
readonly top?: string;
readonly right?: string;
readonly bottom?: string;
readonly left?: string;
readonly header?: string;
readonly footer?: string;
readonly gutter?: string;
readonly linePitch?: string;
readonly pos?: string | number; // Little strange. Perhaps it is normal. Need to clarify in the spec.
}
export class Attributes extends XmlAttributeComponent<IAttributesProperties> {
protected xmlKeys = {
protected readonly xmlKeys = {
val: "w:val",
color: "w:color",
space: "w:space",

View File

@ -1,7 +1,8 @@
import { IXmlableObject } from "./xmlable-object";
export abstract class BaseXmlComponent {
protected rootKey: string;
protected readonly rootKey: string;
// tslint:disable-next-line:readonly-keyword
protected deleted: boolean = false;
constructor(rootKey: string) {

View File

@ -4,8 +4,9 @@ import { IXmlableObject } from "./xmlable-object";
export type AttributeMap<T> = { [P in keyof T]: string };
export abstract class XmlAttributeComponent<T> extends BaseXmlComponent {
// tslint:disable-next-line:readonly-keyword
protected root: T;
protected xmlKeys: AttributeMap<T>;
protected readonly xmlKeys: AttributeMap<T>;
constructor(properties: T) {
super("_attr");

View File

@ -3,6 +3,7 @@ import { IXmlableObject } from "./xmlable-object";
export { BaseXmlComponent };
export abstract class XmlComponent extends BaseXmlComponent {
// tslint:disable-next-line:readonly-keyword
protected root: Array<BaseXmlComponent | string>;
constructor(rootKey: string) {

View File

@ -1,8 +1,8 @@
export interface IXmlAttribute {
[key: string]: string | number | boolean;
readonly [key: string]: string | number | boolean;
}
export interface IXmlableObject extends Object {
_attr?: IXmlAttribute;
readonly _attr?: IXmlAttribute;
}
// Needed because of: https://github.com/s-panferov/awesome-typescript-loader/issues/432