Expose children via js_getChildren

This commit is contained in:
Jordan Eldredge 2019-09-18 20:55:02 -07:00
parent ae32220624
commit 416377fb1c
4 changed files with 13 additions and 9 deletions

View file

@ -609,12 +609,9 @@ function DummyComponent({ makiObject }) {
}
function MakiChildren({ makiObject }) {
if (makiObject.children == null) {
return null;
}
return makiObject.children.map((childMakiObject, i) => (
<Maki key={i} makiObject={childMakiObject} />
));
return makiObject
.js_getChildren()
.map((childMakiObject, i) => <Maki key={i} makiObject={childMakiObject} />);
}
// Given a skin XML node, pick which component to use, and render it.

View file

@ -175,6 +175,7 @@ async function parseChildren(node, children, zip, store) {
childParser = noop;
}
const parsedChild = await childParser(child, node, zip, store);
child.maki = parsedChild;
if (child.children != null && child.children.length > 0) {
await parseChildren(parsedChild, child.children, zip, store);
}

View file

@ -92,7 +92,7 @@ class Container extends MakiObject {
getcurlayout() {
unimplementedWarning("getcurlayout");
// TODO: For now we just always show the first layout. I think that's the default.
return this.children.find(childNode => {
return this.js_getChildren().find(childNode => {
return childNode.getclassname() === "Layout";
});
}

View file

@ -1,8 +1,9 @@
import Emitter from "../Emitter";
import * as Utils from "../utils";
import { ModernStore, ResolvedXmlNode } from "../types";
import { ModernStore, XmlNode } from "../types";
class MakiObject {
_node: XmlNode;
name: string;
_uid: number;
_store: ModernStore;
@ -13,11 +14,12 @@ class MakiObject {
js_annotations: Object;
constructor(
node: ResolvedXmlNode,
node: XmlNode,
parent: MakiObject,
annotations: Object = {},
store: ModernStore
) {
this._node = node;
this._store = store;
if (node) {
this._uid = node.uid;
@ -47,6 +49,10 @@ class MakiObject {
this.children = this.children.filter(item => item !== child);
}
js_getChildren(): MakiObject[] {
return this.children;
}
js_delete() {
this.parent.js_removeChild(this);
this.parent.js_trigger("js_update");