From 81cf6047f9da56e360bb3a80e51a40d4c89a7469 Mon Sep 17 00:00:00 2001 From: David Wheatley Date: Fri, 13 May 2022 22:02:55 +0100 Subject: [PATCH] fix: call abstract `Notification` methods with fallback Only call Notification methods if they are defined, falling back to `undefined` if not through the use of the optional chaining operator. --- .../core/js/src/forum/components/Notification.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/framework/core/js/src/forum/components/Notification.tsx b/framework/core/js/src/forum/components/Notification.tsx index a0acdac33..c91ff8df5 100644 --- a/framework/core/js/src/forum/components/Notification.tsx +++ b/framework/core/js/src/forum/components/Notification.tsx @@ -13,6 +13,8 @@ export interface INotificationAttrs extends ComponentAttrs { notification: NotificationModel; } +// TODO [Flarum 2.0]: Remove `?.` from abstract function calls. + /** * The `Notification` component abstract displays a single notification. * Subclasses should implement the `icon`, `href`, and `content` methods. @@ -20,7 +22,7 @@ export interface INotificationAttrs extends ComponentAttrs { export default abstract class Notification extends Component { view(vnode: Mithril.Vnode) { const notification = this.attrs.notification; - const href = this.href(); + const href = this.href?.() ?? ''; const fromUser = notification.fromUser(); @@ -32,9 +34,9 @@ export default abstract class Notification {avatar(fromUser || null)} - {icon(this.icon(), { className: 'Notification-icon' })} + {icon(this.icon?.(), { className: 'Notification-icon' })} - {this.content()} + {this.content?.()} {humanTime(notification.createdAt())} @@ -51,7 +53,7 @@ export default abstract class Notification )} -
{this.excerpt()}
+
{this.excerpt?.()}
); }