From e2240a67cd81c283d378d69f5b6d7b908dc17112 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sat, 21 Sep 2019 13:51:25 -0700 Subject: [PATCH] Clean up System a tiny bit --- modern/src/runtime/MakiObject.ts | 15 +++++++++++++-- modern/src/runtime/System.ts | 23 ++++++++++++----------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/modern/src/runtime/MakiObject.ts b/modern/src/runtime/MakiObject.ts index 17b3e275..de955d54 100644 --- a/modern/src/runtime/MakiObject.ts +++ b/modern/src/runtime/MakiObject.ts @@ -15,13 +15,24 @@ class MakiObject { children: MakiObject[]; js_annotations: Object; - constructor(node: XmlNode, parent: MakiObject, annotations: Object = {}) { - this._node = node; + constructor( + node: XmlNode | null, + parent: MakiObject, + annotations: Object = {} + ) { if (node) { + this._node = node; this._uid = node.uid; this.attributes = node.attributes || {}; this.name = node.name; } else { + // This feels like a hack. + this._node = { + children: [], + attributes: {}, + uid: Utils.getId(), + name: this.getclassname().toLowerCase(), + }; this._uid = Utils.getId(); // When dynamically creating an object with `new` we have no underlying node this.attributes = {}; diff --git a/modern/src/runtime/System.ts b/modern/src/runtime/System.ts index a135ac72..f46eccc1 100644 --- a/modern/src/runtime/System.ts +++ b/modern/src/runtime/System.ts @@ -13,19 +13,19 @@ import { Context } from "react"; import GuiObject from "./GuiObject"; class System extends MakiObject { - scriptGroup: Group; - root: MakiObject; + _scriptGroup: Group; + _root: MakiObject; _store: ModernStore; _privateInt: Map>; _privateString: Map>; - constructor(scriptGroup, store: ModernStore) { - super(null, null, {}); + constructor(scriptGroup: Group | null, store: ModernStore) { + super(null, null); this._store = store; - this.scriptGroup = scriptGroup == null ? new Group() : scriptGroup; - this.root = scriptGroup; - while (this.root.parent) { - this.root = this.root.parent; + this._scriptGroup = scriptGroup == null ? new Group() : scriptGroup; + this._root = this._scriptGroup; + while (this._root.parent) { + this._root = this._root.parent; } // TODO: Replace these with a DefaultMap once we have one. this._privateInt = new Map(); @@ -47,11 +47,11 @@ class System extends MakiObject { } getscriptgroup() { - return this.scriptGroup; + return this._scriptGroup; } getcontainer(id: string) { - return findDescendantByTypeAndId(this.root, "container", id); + return findDescendantByTypeAndId(this._root, "container", id); } getruntimeversion() { @@ -127,6 +127,7 @@ class System extends MakiObject { if (!this._privateInt.has(section)) { return defvalue; } + // @ts-ignore We know this section exists return this._privateInt.get(section).get(item); } @@ -508,7 +509,7 @@ class System extends MakiObject { } // Based on https://stackoverflow.com/questions/11887934/how-to-check-if-the-dst-daylight-saving-time-is-in-effect-and-if-it-is-whats - _stdTimezoneOffset(date) { + _stdTimezoneOffset(date: Date): number { const jan = new Date(date.getFullYear(), 0, 1); const jul = new Date(date.getFullYear(), 6, 1); return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());