Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New best practice: event dispatching #224

Open
geoffrich opened this issue Oct 4, 2021 · 3 comments
Open

New best practice: event dispatching #224

geoffrich opened this issue Oct 4, 2021 · 3 comments

Comments

@geoffrich
Copy link
Contributor

geoffrich commented Oct 4, 2021

It is a good practice to dispatch events from components after rendering has completed, so that the event's listeners see the fully rendered state of the component. To do so, you can await the updateComplete Promise before firing the event.
-- Lit docs

We ran into this issue with the valuetile. Code was listening to the fareClick event and expecting the attribute to be set. However, the attribute was not set until after updateComplete.

Code example from Lit docs:

async _loginClickHandler() {
  this.loggedIn = true;
  // Wait for `loggedIn` state to be rendered to the DOM
  await this.updateComplete;
  this.dispatchEvent(new Event('login'));
}

Reference PR for the discovery of the use case
https://github.com/AlaskaAirlines/auro-valuetile/pull/31

@geoffrich
Copy link
Contributor Author

We should also mention that you should only await update complete after completing all the property updates.

// INCORRECT
// do something
await this.updateComplete
// do more things
this.dispatchEvent

// CORRECT
// do something
// do more things
await this.updateComplete
this.dispatchEvent

@settings settings bot removed the not-reviewed label Oct 12, 2021
@blackfalcon blackfalcon added the not-reviewed Issue has not been reviewed by Auro team members label Oct 13, 2021
@braven112 braven112 added this to the wc-generator v4.0-rc milestone Dec 21, 2021
@braven112 braven112 removed the not-reviewed Issue has not been reviewed by Auro team members label Dec 21, 2021
@blackfalcon
Copy link
Member

This issue is bound to AlaskaAirlines/auro-radio#26

@blackfalcon blackfalcon removed their assignment Jan 31, 2022
@blackfalcon blackfalcon removed this from the wc-generator v4.0-rc milestone May 5, 2022
@blackfalcon blackfalcon added the not-reviewed Issue has not been reviewed by Auro team members label May 6, 2022
@blackfalcon blackfalcon added this to the wc-generator doc updates milestone Jun 17, 2022
@blackfalcon blackfalcon added auro-generator and removed not-reviewed Issue has not been reviewed by Auro team members labels Jun 17, 2022
@blackfalcon blackfalcon added not-reviewed Issue has not been reviewed by Auro team members and removed Status: help wanted labels Jan 20, 2023
@settings settings bot removed the auro-generator label May 9, 2023
@blackfalcon
Copy link
Member

I have a feeling that we are doing this with the latest versions of new components. @jason-capsule42 can you validate? And if we are, let's document this pattern as a 'best practice' for new developer onboarding.

@jason-capsule42 jason-capsule42 removed Type: Documentation Documentation only changes not-reviewed Issue has not been reviewed by Auro team members labels Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants