remove from API delete()/IsDeleted(), and deleted check from prepForXml; not useful in declarative style API

This commit is contained in:
Tom Hunkapiller
2021-05-22 03:19:06 +03:00
parent 37d099b457
commit ff14fcae3a
5 changed files with 7 additions and 75 deletions

View File

@ -9,16 +9,10 @@ export interface IContext {
export abstract class BaseXmlComponent {
protected readonly rootKey: string;
// tslint:disable-next-line:readonly-keyword
protected deleted: boolean = false;
constructor(rootKey: string) {
this.rootKey = rootKey;
}
public abstract prepForXml(context: IContext): IXmlableObject | undefined;
public get IsDeleted(): boolean {
return this.deleted;
}
}

View File

@ -20,28 +20,24 @@ const xmlString = `
`;
const convertedXmlElement = {
deleted: false,
root: [
{
deleted: false,
rootKey: "w:p",
root: [
{ deleted: false, rootKey: "_attr", root: { "w:one": "value 1", "w:two": "value 2" } },
{ deleted: false, rootKey: "w:rPr", root: [{ deleted: false, rootKey: "w:noProof", root: ["some value"] }] },
{ rootKey: "_attr", root: { "w:one": "value 1", "w:two": "value 2" } },
{ rootKey: "w:rPr", root: [{ rootKey: "w:noProof", root: ["some value"] }] },
{
deleted: false,
rootKey: "w:r",
root: [
{ deleted: false, rootKey: "_attr", root: { active: "true" } },
{ deleted: false, rootKey: "w:t", root: ["Text 1"] },
{ rootKey: "_attr", root: { active: "true" } },
{ rootKey: "w:t", root: ["Text 1"] },
],
},
{
deleted: false,
rootKey: "w:r",
root: [
{ deleted: false, rootKey: "_attr", root: { active: "true" } },
{ deleted: false, rootKey: "w:t", root: ["Text 2"] },
{ rootKey: "_attr", root: { active: "true" } },
{ rootKey: "w:t", root: ["Text 2"] },
],
},
],

View File

@ -1,8 +1,7 @@
import { expect } from "chai";
import { Formatter } from "export/formatter";
import { EMPTY_OBJECT, XmlComponent } from "./";
import { IContext } from "./base";
import { XmlComponent } from "./";
class TestComponent extends XmlComponent {}
@ -21,21 +20,4 @@ describe("XmlComponent", () => {
});
});
});
describe("#prepForXml()", () => {
it("should skip deleted elements", () => {
const child = new TestComponent("w:test1");
child.delete();
xmlComponent.addChildElement(child);
// tslint:disable-next-line: no-object-literal-type-assertion
const xml = xmlComponent.prepForXml({} as IContext);
if (!xml) {
return;
}
expect(xml["w:test"]).to.deep.equal(EMPTY_OBJECT);
});
});
});

View File

@ -14,12 +14,6 @@ export abstract class XmlComponent extends BaseXmlComponent {
public prepForXml(context: IContext): IXmlableObject | undefined {
const children = this.root
.filter((c) => {
if (c instanceof BaseXmlComponent) {
return !c.IsDeleted;
}
return c !== undefined;
})
.map((comp) => {
if (comp instanceof BaseXmlComponent) {
return comp.prepForXml(context);
@ -44,10 +38,6 @@ export abstract class XmlComponent extends BaseXmlComponent {
return this;
}
public delete(): void {
this.deleted = true;
}
}
export abstract class IgnoreIfEmptyXmlComponent extends XmlComponent {