-
Notifications
You must be signed in to change notification settings - Fork 10
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
Possible new lifecycle hook #9
Comments
The following works :-)
But I am wondering whether we should just render immediately when connected. What is your opinion @justinfagnani ? |
yeah, I saw you did the same thing on invalidate... or maybe the connectedCallback could actually return a promise that resolves? this seems kind of "hacky" and async/await compiles down to crap (huge pile actually) for IE11 support... |
That is exactly what it does today. It returns a promise which resolves :-) You could also do
But as I said, we could probably just let |
super.connectedCallback currently returns undefined... do you have something locally or on another branch? |
Ah it uses to return the result of |
I personally wouldn't return anything from connectedCallback() that's changing the signature, and subclasses might not forward the return value... edit: "wouldn't" not "would" :) |
that is a valid point... what would you suggest? lifecycle hook or something completely different? |
@justinfagnani so any downsides to forcing a render in connectedCallback? (ie. no microtask) |
There's a few ways to do this:
I think 1) is best if possible. In this case I think it highlights a data-dependency questions that seems currently unanswered in your example: Should setting export class ProductItemElement extends LitElement {
static get properties() {
return {
product: {
type: Object
},
};
}
get favorite() { return this.product && this.product.isFavorite; }
} |
Mainly that all the data from above might not be there yet. Usually, just having property initializers is enough to kick off rendering. For the rare element that doesn't initialize any properties, calling |
I was thinking for cases where you might want to do (Typing on phone) this.canvas = this.$('myCanvas'); which requires the Dom to exist |
Should we add a lifecycle hook for when properties have data - before the first render, so we can do some stuff.
If I want to set a property based on another property, I have to do some not-so-nice settimeout-0 stuff to make it work...
I put it in my demo to show the usecase:
https://github.com/filipbech/lit-element-example/blob/master/demo.js#L69-L71
What do you think? wouldn't this be a nice handle, or am I missing something obvious?
The text was updated successfully, but these errors were encountered: