diff --git a/projects/emfular/src/lib/referencing/referencable/container/link/re-link-list-container.ts b/projects/emfular/src/lib/referencing/referencable/container/link/re-link-list-container.ts index 2db6574..1fc2b5b 100644 --- a/projects/emfular/src/lib/referencing/referencable/container/link/re-link-list-container.ts +++ b/projects/emfular/src/lib/referencing/referencable/container/link/re-link-list-container.ts @@ -45,6 +45,12 @@ implements ReLinkContainer { return res; //todo behaviour of flag different to add?? } + override delete(mode: DeletionMode = DeletionMode.RELAXED): void { + while (this._instance.length > 0) { + this.remove(this._instance[0], mode); + } + } + removeFromInverse(item: T, mode: DeletionMode = DeletionMode.RELAXED): boolean { if(this.inverseName !== undefined) { for (const child of [...this._instance]) { diff --git a/projects/emfular/src/lib/referencing/test/delete-on-re-containers.spec.ts b/projects/emfular/src/lib/referencing/test/delete-on-re-containers.spec.ts new file mode 100644 index 0000000..7f40eb8 --- /dev/null +++ b/projects/emfular/src/lib/referencing/test/delete-on-re-containers.spec.ts @@ -0,0 +1,64 @@ +import {Middle2WithChildren, ReChild3, RootWithChildren} from "./referencables-with-children"; +import {DeletionMode} from "../../utils/deletion-mode"; + +describe('ReContainer delete tests', () => { + it("should relaxed delete re-tree-container correctly", () =>{ + let root = new RootWithChildren(); + let child1 = new ReChild3(); + let child2 = new ReChild3(); + let middle = new Middle2WithChildren(); + root.link3.push(child1,child2); + middle.child3.push(child1,child2); + expect(root.link3.length).toBe(2); + expect(child1.link1).toContain(root); + expect(child2.link1).toContain(root); + expect(middle.child3.length).toBe(2); + expect(child1.parentPointer).toEqual(middle); + expect(child2.parentPointer).toEqual(middle); + middle.child3.delete(); + expect(root.link3.length).toBe(2); + expect(middle.child3.length).toBe(0); + expect(child1.parentPointer).toBeUndefined(); + expect(child2.parentPointer).toBeUndefined(); + }) + + it("should cascade delete re-tree-container correctly", () =>{ + let root = new RootWithChildren(); + let child1 = new ReChild3(); + let child2 = new ReChild3(); + let middle = new Middle2WithChildren(); + root.link3.push(child1,child2); + middle.child3.push(child1,child2); + expect(root.link3.length).toBe(2); + expect(child1.link1).toContain(root); + expect(child2.link1).toContain(root); + expect(middle.child3.length).toBe(2); + expect(child1.parentPointer).toEqual(middle); + expect(child2.parentPointer).toEqual(middle); + middle.child3.delete(); + expect(root.link3.length).toBe(2); + expect(middle.child3.length).toBe(0); + expect(child1.parentPointer).toBeUndefined(); + expect(child2.parentPointer).toBeUndefined(); + }) + + it("should delete re-list-container correctly", () =>{ + let root = new RootWithChildren(); + let child1 = new ReChild3(); + let child2 = new ReChild3(); + let middle = new Middle2WithChildren(); + root.link3.push(child1,child2); + middle.child3.push(child1,child2); + expect(root.link3.length).toBe(2); + expect(child1.link1).toContain(root); + expect(child2.link1).toContain(root); + expect(middle.child3.length).toBe(2); + expect(child1.parentPointer).toEqual(middle); + expect(child2.parentPointer).toEqual(middle); + root.link3.delete(); + expect(root.link3.length).toBe(0); + expect(middle.child3.length).toBe(2); + expect(child1.parentPointer).toBeDefined(); + expect(child2.parentPointer).toBeDefined(); + }) +}); \ No newline at end of file