make props a always defined property

This commit is contained in:
Géry Debongnie
2019-01-29 20:49:51 +01:00
parent 0b3dc0301e
commit bc6bf5354f
2 changed files with 8 additions and 3 deletions
+7 -2
View File
@@ -46,7 +46,7 @@ export class Widget<T extends WEnv, Props> {
env: T; env: T;
state: Object = {}; state: Object = {};
props: Props | undefined; props: Props;
refs: { [key: string]: Widget<T, {}> | HTMLElement | undefined } = {}; refs: { [key: string]: Widget<T, {}> | HTMLElement | undefined } = {};
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@@ -55,7 +55,12 @@ export class Widget<T extends WEnv, Props> {
constructor(parent: Widget<T, {}> | T, props?: Props) { constructor(parent: Widget<T, {}> | T, props?: Props) {
wl.push(this); wl.push(this);
this.props = props;
// is this a good idea?
// Pro: if props is empty, we can create easily a widget
// Con: this is not really safe
// Pro: but creating widget (by a template) is always unsafe anyway
this.props = <Props>props;
let id: number; let id: number;
let p: Widget<T, any> | null = null; let p: Widget<T, any> | null = null;
if (parent instanceof Widget) { if (parent instanceof Widget) {
+1 -1
View File
@@ -19,6 +19,6 @@ export class Notification extends Widget<Env, INotification> {
template = template; template = template;
close() { close() {
this.env.notifications.close(this.props!.id); this.env.notifications.close(this.props.id);
} }
} }