lit-element-starter-ts | Sample component project using LitElement with TypeScript | Web Framework library
kandi X-RAY | lit-element-starter-ts Summary
kandi X-RAY | lit-element-starter-ts Summary
This project includes a sample component using LitElement with TypeScript.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of lit-element-starter-ts
lit-element-starter-ts Key Features
lit-element-starter-ts Examples and Code Snippets
Community Discussions
Trending Discussions on lit-element-starter-ts
QUESTION
I want to compose a LitElement widget from two other widgets. The basic idea would be that one "selector" widget selects something, send an event to its parent "mediator" one, which in turns would update the related property in a "viewer" child widget (event up, property down). This follows the "mediator pattern" example of the documentation about composition, only that I need to deal with fully separated classes.
Below is a minimum working example, which builds and run in the LitElement TypeScript starter template project, with all dependencies force-updated with ncu --upgradeAll
.
The desired behavior would be that the Viewer widget does render the item["name"]
when the user selects something in the dropdown list.
So far, I managed to send an event up from the Selector to the Mediator, and to update the item_id
attribute within the Viewer. However, this does not seem to trigger an update of the item_id
property of the Viewer.
The approach used is to override updated
in the Mediator (l.36), loop through its children and do a child.setAttribute
, which is probably highly inelegant. There is surely another —cleaner— way, but I failed to clearly understand the update sequence of Lit.
ANSWER
Answered 2022-Mar-31 at 09:48You are setting the item only in the connectedCallback. Better you get the item dynamically via getter.
Regarding your question of setting an attribute of a slotted element, there is in my opinion no other way than programmatically.
QUESTION
I would like to convert my existing Javascript CustomElements/WebComponents (made with Lit v1 and ported to v2) to TypeScript.
Example:
...ANSWER
Answered 2022-Jan-06 at 12:54Lit's @property
decorator is all about setting up a reactive property AND reflecting the attribute to the value (and vice versa if you turn on reflect: true
). However, this conversion for HTML elements is tricky on non-string values, e.g. numbers shall be parsed to an actual number, for a boolean value the existence of the attribute means true
etc.
That is why Lit needs type
, to be able to choose the correct converter for the attribute value. Think of it as a type-hint or a converter-type regarding attribute/value conversion. Take a look at
Lit's default converter.
Your actual types should be defined in TypeScript.
QUESTION
The Typescript Lit Element starter project includes this global interface declaration at the bottom of the example element:
...ANSWER
Answered 2020-Dec-18 at 12:30Is that necessary?
No, this declaration is not necessary for your LitElement based custom element to work.
What is it used for?
This is a feature of TypeScript and not specific to LitElement.
This declaration helps TypeScript to provide strong typing when interacting with DOM APIs. The JavaScript DOM API of course does not know or care about types, but TypeScript does. With this mechanism you can add the type of your custom elements to the DOM APIs.
An example might illustrate this better. Assuming this very simple custom element:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lit-element-starter-ts
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page