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

refactor(lit): update lit examples with current patterns #268

Merged
merged 4 commits into from
Oct 27, 2024

Conversation

lloydrichards
Copy link
Contributor

Goals/Scope

I was using ComponentParty to help learn lit a couple months back and found it super helpful to compare the lifecycle methods of React vs Lit. Now with some more experiance I've notced that the lit examples are a little out of date with the current state of Lit/Lab.

In this PR i want to double check all the examples and add more modern patterns if possible, the current obvious one is the use .map() instead of the repeat directive.

Description

I noticed two patterns that I was able to upgrade:

repeat

While mapping over the array does work to render multiple items, lit provides the repeat directive which allows a key function to be passed helping make rerenders more performant.

Since React and other frameworks do this with the key prop directly in the returnd tag, I think its best to use the same permormance patterns.

task

Lit also provides a better way to manage async tasks with the task package. Defining a task can be return all the pattern matching on state without having to track it in the component. Makes for a much cleaner implementation.

Comments

Let me know if you want anything changed or updated 👍

@lloydrichards lloydrichards force-pushed the refactor/update-lit-templates branch from 9f7b782 to 714a3e7 Compare October 14, 2024 20:10
@lloydrichards
Copy link
Contributor Author

👋 @matschik

Just want to poke and see if there is anything you're missing from my side for this 😄

@matschik
Copy link
Owner

matschik commented Oct 27, 2024

task is very interesting !

About repeat suggestion, from Lit documentation (https://lit.dev/docs/templates/directives/#repeat):

If you're not using a key function, you should consider using map().

As you said, since we are using key in iteration on other examples, let's do it !

Ok good for me ! Thank you very much for your contribution and patience 🙏

@matschik matschik merged commit 6267426 into matschik:main Oct 27, 2024
1 check passed
@lloydrichards lloydrichards deleted the refactor/update-lit-templates branch October 27, 2024 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants