Evaluate component attrs before use

This commit is contained in:
Zaid Abdulla committed 2021-10-24 18:17:03 -07:00
1 parent 73baffc3b9
commit 88a84788a5
7 files changed
+26 -16

No files matched your search

+7 -3
View File
@@ -19,18 +19,22 @@
import { ClosureComponent, Component } from "mithril";
import { m } from "../components";
import { evaluateExpression } from "../store";
const component: ClosureComponent = (): Component => {
return {
view: (vnode) => {
let deviceId;
if (vnode.attrs["device"])
deviceId = vnode.attrs["device"]["DeviceID.ID"].value[0];
const device = vnode.attrs["device"];
if (device) deviceId = device["DeviceID.ID"].value[0];
const children = Object.values(vnode.attrs["components"]).map((c) => {
if (Array.isArray(c)) c = evaluateExpression(c, device || {});
if (typeof c !== "object") return `${c}`;
const type = evaluateExpression(c["type"], device || {});
if (!type) return null;
const attrs = Object.assign({}, vnode.attrs, c);
return m(attrs["type"], attrs);
return m(type as string, attrs);
});
if (deviceId) {
return m(