Overview
The osagai/lifecycles
module has functions for listening to lifecyles of the custom element. Use this module if you need to define different callbacks which are fired at different points in the element's lifecycle.
Lifecycles
Connected
A custom element is consider as connected when the element is appended into a document. This will also happen when the element is moved.
Disconnected
The custom element is disconnected when it is removed from the document. It could be useful for any necessary cleanup like subscriptions or cancelling network requests.
Attribute changed
This is invoked when an attribute from the observedAttributes
list is added, changed or removed. This could be useful to make network request for updating the data.
onAttributeChanged(element, ({ name, current }) => {
if (name === 'userID') {
update(element, async () => {
return await api.getUser(current)
})
}
})