refactor(lit): update lit examples with current patterns #268
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 therepeat
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 👍