Last active
March 29, 2020 21:03
-
-
Save jfbrennan/b59a6e4ece6d5397ef00b4bc11a33af6 to your computer and use it in GitHub Desktop.
Riot component with all the basics
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
<my-todos> | |
<p>Todo count: {state.todos.length}</p> | |
<input ref="newTodo" type="text"> | |
<button onclick="{add}">Add</button> | |
<ul if="{state.todos.length}"> | |
<li each="{(todo, i) in state.todos}" key="{i}">{todo} <button onclick="{e => remove(i)}">Remove</button></li> | |
</ul> | |
<script> | |
export default { | |
// Lifecycle methods: https://riot.js.org/api/#lifecycle | |
state: { | |
todos: [] | |
}, | |
add(e) { | |
const todo = this.$('[ref="newTodo"]').value; | |
this.state.todos.push(todo); | |
this.update(); | |
}, | |
remove(i) { | |
this.state.todos.splice(i, 1); | |
this.update(); | |
} | |
} | |
</script> | |
<style> | |
ul { list-style: none } | |
</style> | |
</my-todos> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment