mirror of https://github.com/TriliumNext/Notes
chore(types): allow containers to constrain children
parent
4cfb0d6161
commit
6d41af98fd
@ -1,18 +0,0 @@
|
||||
import BasicWidget from "../basic_widget.js";
|
||||
|
||||
export default class Container extends BasicWidget {
|
||||
doRender() {
|
||||
this.$widget = $(`<div>`);
|
||||
this.renderChildren();
|
||||
}
|
||||
|
||||
renderChildren() {
|
||||
for (const widget of this.children) {
|
||||
try {
|
||||
this.$widget.append(widget.render());
|
||||
} catch (e) {
|
||||
widget.logRenderingError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
import Component, { TypedComponent } from "../../components/component.js";
|
||||
import BasicWidget, { TypedBasicWidget } from "../basic_widget.js";
|
||||
|
||||
export default class Container<T extends TypedComponent<any>> extends TypedBasicWidget<T> {
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(`<div>`);
|
||||
this.renderChildren();
|
||||
}
|
||||
|
||||
renderChildren() {
|
||||
for (const widget of this.children) {
|
||||
if (!("render" in widget)) {
|
||||
throw "Non-renderable widget encountered.";
|
||||
}
|
||||
|
||||
const typedWidget = widget as unknown as TypedBasicWidget<any>;
|
||||
|
||||
try {
|
||||
if ("render" in widget) {
|
||||
this.$widget.append(typedWidget.render());
|
||||
}
|
||||
|
||||
} catch (e: any) {
|
||||
typedWidget.logRenderingError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue