Last active
July 5, 2020 09:43
-
-
Save MatthiasKainer/e5f14d5ef2dabe85d4b024e28a0f1139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const clickReducer = (state: number) => ({ | |
add: (payload: number) => state + (payload as number ?? 0) | |
}) | |
pureLit( | |
"todo-list", | |
(element: LitElementWithProps<ListProps>) => html`<ul> | |
${element.items.map( | |
(item) => | |
html`<li | |
@click="${() => | |
element.dispatchEvent(new CustomEvent("remove", { detail: item }))}" | |
> | |
${item} | |
</li>` | |
)} | |
</ul>`, | |
{ | |
styles: [blockElement], | |
defaults: { items: [] }, | |
} | |
); | |
pureLit( | |
"todo-add", | |
(element) => { | |
const { getState, publish } = useState(element, { value: "" }); | |
return html` | |
<input | |
type="text" name="item" value="${getState().value}" | |
@input="${(e: InputEvent) => | |
publish({ value: (e.target as HTMLInputElement)?.value })}" | |
placeholder="insert new item" | |
/> | |
<button | |
@click=${() => element.dispatchEvent(new CustomEvent("add", { detail: getState().value }))} | |
> | |
Add Event | |
</button> | |
`; | |
}, | |
{ styles: [blockElement] } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment