Last active
May 18, 2019 17:47
-
-
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.
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
<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