Skip to content

Instantly share code, notes, and snippets.

@Aveek-Saha
Last active May 18, 2019 17:47
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 Aveek-Saha/1a85fc79687a75ca04e49c65776d7b64 to your computer and use it in GitHub Desktop.
Save Aveek-Saha/1a85fc79687a75ca04e49c65776d7b64 to your computer and use it in GitHub Desktop.
A simple Svelte todo app, copy paste this in the src/App.svelte file in the svelte boilerplate.
<script>
let task = "";
let todos = ["eat", "sleep", "code"]
function addTask() {
if(task!=""){
todos.push(task)
todos = todos;
task = ""
}
}
function addNew(event) {
if (event.which === 13) {
addTask()
}
}
function removeTask(index) {
todos = todos.slice(0, index).concat(todos.slice(index + 1));
console.log(index);
}
</script>
<style>
ul {
list-style: none;
}
</style>
<input bind:value={task} on:keydown={addNew}>
<button on:click={addTask}>Add Task</button>
<ul>
{#each todos as todo, index (todo)}
<li>
<input type=checkbox on:click={() => removeTask(index)}>
{todo}
</li>
{/each}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment