-
Notifications
You must be signed in to change notification settings - Fork 39
Add onAttach
and onDetach
lifecycle hooks
#771
Conversation
@@ -169,6 +175,14 @@ export class WidgetBase<P = WidgetProperties, C extends DNode = DNode> implement | |||
// Do nothing by default. | |||
} | |||
|
|||
protected onAttach(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any thought to this just being an optional method on WidgetBaseInterface
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, you will essentially always do a noop on most widgets on attachment, and I don't know the performance impact, but invoking potentially hundreds of the same function seems 😕 where as testing for presence and only calling if present feels like it would be more efficient...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do the same for the onElementCreated
/ onElementUpdated
, these guys get called on requestIdleCallback
so certainly should reduce/negate the performance impact - but I can look at the optional method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem is I don't want to put it on the interface (it's protected), so I don't think we can type it as such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, optional abstract isn't allowed and protected cannot be enforced on an interface... You ruin all my best ideas... 😝
Type: feature
The following has been addressed in the PR:
Description:
Adds two lifecycle methods
onAttach
andonDetach
for when a widget has attached and when it is detached.Resolves #766