Refactor components

Implement context mechanism to pass default attributes to descendant
components.
This commit is contained in:
Zaid Abdulla committed 2019-02-12 23:11:27 -08:00
1 parent d46d133878
commit ee8c43747e
35 files changed
+1903 -1831

No files matched your search

+23 -24
View File
@@ -1,29 +1,28 @@
"use strict";
import m from "mithril";
import * as components from "../components";
import { m } from "../components";
const component = {
view: vnode => {
let deviceId;
if (vnode.attrs.device)
deviceId = vnode.attrs.device["DeviceID.ID"].value[0];
export default function component() {
return {
view: vnode => {
let deviceId;
if (vnode.attrs.device)
deviceId = vnode.attrs.device["DeviceID.ID"].value[0];
const children = Object.values(vnode.attrs.components).map(c => {
if (typeof c !== "object") return `${c}`;
const attrs = Object.assign({}, vnode.attrs, c);
return m(components.get(attrs.type), attrs);
});
if (deviceId) {
return m(
"a",
{ href: `#!/devices/${encodeURIComponent(deviceId)}` },
children
);
} else {
return children;
const children = Object.values(vnode.attrs.components).map(c => {
if (typeof c !== "object") return `${c}`;
const attrs = Object.assign({}, vnode.attrs, c);
return m(attrs.type, attrs);
});
if (deviceId) {
return m(
"a",
{ href: `#!/devices/${encodeURIComponent(deviceId)}` },
children
);
} else {
return children;
}
}
}
};
export default component;
};
}