Skip to content

Commit

Permalink
Fix setting internal value in renderedCallback (#51)
Browse files Browse the repository at this point in the history
Use connectedCallback instead, this avoid having to deal with the null check
And also it ensure we don't need to check if parent is present in the disconnectedCallback
  • Loading branch information
scolladon authored Jun 6, 2020
1 parent 28db0a8 commit 87bbc4b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions force-app/main/default/lwc/baseAttribute/baseAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@ export default class BaseAttribute extends LightningElement {
}

// Attach parent to handle disconnectedCallback gracefully
renderedCallback() {
connectedCallback() {
this._parent = this.template.host.parentNode;
}

// disconnectedCallback is called after having remove template
// need to call the disconnect from on the parent
disconnectedCallback() {
if (this._parent) {
this._parent.dispatchEvent(
new CustomEvent(DISCONNECT_EVENT_NAME, {
bubbles: true,
detail: {
option: this._option,
payload: this._payload
}
})
);
}
this._parent.dispatchEvent(
new CustomEvent(DISCONNECT_EVENT_NAME, {
bubbles: true,
detail: {
option: this._option,
payload: this._payload
}
})
);
}

// dispatch the _eventName event to the parent
Expand Down

0 comments on commit 87bbc4b

Please sign in to comment.