From 8ed22cf414fb0168604ee1bfbc722f88debb0f01 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 14 Oct 2019 08:52:46 -0700 Subject: [PATCH] Make parent optional --- modern/src/runtime/MakiObject.ts | 7 +++++-- modern/src/runtime/PopupMenu.ts | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modern/src/runtime/MakiObject.ts b/modern/src/runtime/MakiObject.ts index de955d54..e3bac7af 100644 --- a/modern/src/runtime/MakiObject.ts +++ b/modern/src/runtime/MakiObject.ts @@ -10,14 +10,14 @@ class MakiObject { // type conversion differently. Having one type that holds both the pre and // post type coerced values is too confusing. attributes: { [key: string]: string | number | boolean | undefined }; - parent: MakiObject; + parent: MakiObject | null; _emitter: Emitter; children: MakiObject[]; js_annotations: Object; constructor( node: XmlNode | null, - parent: MakiObject, + parent: MakiObject | null, annotations: Object = {} ) { if (node) { @@ -61,6 +61,9 @@ class MakiObject { } js_delete() { + if (this.parent == null) { + return; + } this.parent.js_removeChild(this); this.parent.js_trigger("js_update"); } diff --git a/modern/src/runtime/PopupMenu.ts b/modern/src/runtime/PopupMenu.ts index 6df046c5..68591fd4 100644 --- a/modern/src/runtime/PopupMenu.ts +++ b/modern/src/runtime/PopupMenu.ts @@ -17,9 +17,12 @@ type Command = class PopupMenu extends MakiObject { _commands: Command[]; _guiParent: Group; + parent: MakiObject; js_selectCommand: (id: number) => void; + constructor(node: XmlNode, parent: MakiObject, annotations: Object) { super(node, parent, annotations); + this.parent = parent; if (!(parent instanceof Group)) { throw new Error(