Skip to content

Instantly share code, notes, and snippets.

@abalmus
Last active April 22, 2016 14:36
Show Gist options
  • Save abalmus/8b399dfdb80e31737923ab2ec979f87f to your computer and use it in GitHub Desktop.
Save abalmus/8b399dfdb80e31737923ab2ec979f87f to your computer and use it in GitHub Desktop.
Aurelia Todo
<template>
<require from="./todo"></require>
<div class="page-host">
<todo />
</div>
</template>
export class App {}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
</head>
<body aurelia-app="main">
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
aurelia.start().then(a => a.setRoot());
}
.completed {
text-decoration: line-through;
}
<template>
<div>
<ul>
<li repeat.for="todo of todos" click.delegate="toggleTodo(todo)">
<span class="${todo.completed ? 'completed' : ''}">
<span>${todo.id}</span> ${todo.title}
</span>
</li>
</ul>
</div>
<form action="" submit.delegate="addTodo($event)">
<input type="text" value.bind="newTodoTitle">
<button type="submit">Add Todo</button>
</form>
</template>
import {TodoItem} from './TodoItem';
export class Todo {
todos = [];
newTodoTitle;
addTodo(e) {
e.preventDefault();
if (this.newTodoTitle) {
this.todos.push(new TodoItem(this.newTodoTitle));
}
}
toggleTodo(todo) {
todo.toggle();
}
}
let nextTodoId = 0;
export class TodoItem {
constructor(title) {
this.id = nextTodoId++;
this.title = title;
this.completed = false;
}
toggle() {
this.completed = !this.completed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment