Skip to content

Instantly share code, notes, and snippets.

@MatthiasKainer
Last active July 5, 2020 09:42
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/8556228e90fa44d38506c0688475fb8b to your computer and use it in GitHub Desktop.
Save MatthiasKainer/8556228e90fa44d38506c0688475fb8b to your computer and use it in GitHub Desktop.
pureLit("dispatch-todo", (element) => {
const { publish, getState } = useState(element, { todos: [] } as TodoState);
return html`
<h2>Your todos</h2>
<todo-add
@add="${(e: CustomEvent) =>
publish({ todos: [...getState().todos, e.detail] })}"
></todo-add>
<todo-list
.items="${getState().todos}"
@remove="${(e: CustomEvent) =>
publish({
todos: [...getState().todos.filter((todo) => todo !== e.detail)],
})}
}"
></todo-list>
`;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment