mirror of
https://github.com/flarum/core.git
synced 2025-08-11 10:55:47 +02:00
Add error warning if children attr is ever used
This commit is contained in:
committed by
Franz Liedke
parent
e10220ae47
commit
10f4223028
@@ -24,9 +24,7 @@ export default abstract class Component<T extends ComponentAttrs = any> implemen
|
|||||||
abstract view(vnode: Mithril.Vnode<T, this>): Mithril.Children;
|
abstract view(vnode: Mithril.Vnode<T, this>): Mithril.Children;
|
||||||
|
|
||||||
oninit(vnode: Mithril.Vnode<T, this>) {
|
oninit(vnode: Mithril.Vnode<T, this>) {
|
||||||
this.initAttrs(vnode.attrs);
|
this.setAttrs(vnode.attrs);
|
||||||
|
|
||||||
this.attrs = vnode.attrs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
oncreate(vnode: Mithril.VnodeDOM<T, this>) {
|
oncreate(vnode: Mithril.VnodeDOM<T, this>) {
|
||||||
@@ -34,9 +32,7 @@ export default abstract class Component<T extends ComponentAttrs = any> implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
onbeforeupdate(vnode: Mithril.VnodeDOM<T, this>) {
|
onbeforeupdate(vnode: Mithril.VnodeDOM<T, this>) {
|
||||||
this.initAttrs(vnode.attrs);
|
this.setAttrs(vnode.attrs);
|
||||||
|
|
||||||
this.attrs = vnode.attrs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,6 +63,18 @@ export default abstract class Component<T extends ComponentAttrs = any> implemen
|
|||||||
return m(this as any, componentProps, children);
|
return m(this as any, componentProps, children);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setAttrs(attrs: T) {
|
||||||
|
this.initAttrs(attrs);
|
||||||
|
|
||||||
|
if (attrs && 'children' in attrs) {
|
||||||
|
throw new Error(
|
||||||
|
'The "children" attribute of attrs should never be used. Either pass children in as the vnode children or rename the attribute'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.attrs = attrs;
|
||||||
|
}
|
||||||
|
|
||||||
protected initAttrs(attrs: T): T {
|
protected initAttrs(attrs: T): T {
|
||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user