Skip to content

Instantly share code, notes, and snippets.

@MatthiasKainer
Last active July 5, 2020 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthiasKainer/e5f14d5ef2dabe85d4b024e28a0f1139 to your computer and use it in GitHub Desktop.
Save MatthiasKainer/e5f14d5ef2dabe85d4b024e28a0f1139 to your computer and use it in GitHub Desktop.
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