Skip to content

Instantly share code, notes, and snippets.

@ncammarata
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ncammarata/1831e3bcea38d45dc8ab to your computer and use it in GitHub Desktop.
Save ncammarata/1831e3bcea38d45dc8ab to your computer and use it in GitHub Desktop.
v2
store Tasks {
@tasks = []
@undone <- @tasks.filter(task => !task.done)
makeTask(task) { return { title: title, done: false } }
addTask(newText) { @tasks.push(makeTask(newText)) }
clear() { @tasks = @undone }
}
view Task {
<h2>{^data.title}</h2>
<input type="checkbox" checked={^data.done} change={^change()}>
}
view Main {
@newText = ""
add() { Tasks.addTask(@newText); @newText = "" }
<h1>Todo List</h1>
<Task repeat[task]={Tasks.tasks}
data = {task}
change = {bool => task.done = bool} />
<div.toolbar>
<div.undone> {Tasks.undone.length} tasks left</div>
<button click={Tasks.clear()}>clear completed</button>
</div>
<input enter={add()} sync={@newText} placeholder="New Task" />
}
@natew
Copy link

natew commented Apr 16, 2015

store Tasks {
  @tasks = []
  @undone <- @tasks.filter(task => !task.done)

  makeTask(task) { return { title: title, done: false } }

  addTask(newText) { @tasks.push(makeTask(newText)) }
  clear() { @tasks = @undone }
}

view Task {
  <h2>{^title}</h2>
  <input type="checkbox" checked={^done} change={^change}>
}

view Main {
  @newText = ""

  add() { Tasks.addTask(@newText); @newText = "" }

  <h1>Todo List</h1>
  <Task (Task.tasks) change = {bool => task.done = bool} />

  <div.toolbar>
    <div.undone> {Tasks.undone.length} tasks left</div>
    <button click={Tasks.clear()}>clear completed</button>
  </div>

  <input enter={add} sync={@newText} placeholder="New Task" />
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment