Skip to content

Instantly share code, notes, and snippets.

@ncammarata
Created January 11, 2015 03:46
Show Gist options
  • Select an option

  • Save ncammarata/bce98e0e770f44419c15 to your computer and use it in GitHub Desktop.

Select an option

Save ncammarata/bce98e0e770f44419c15 to your computer and use it in GitHub Desktop.
placeholder = "What needs to be done?"
type Filter = All | Active | Complete
filterFn = case Filter of
All: constant True
Complete: (eq .complete)
Active: (not << eq) .complete
App {
state: { filter: All, newText: "", tasks: [] }
action:
add:
@tasks = @tasks :: { done: False, editing: false, text: @newText }
@newText = ""
remove task:
@tasks = filter (eq task) @tasks
clearDone:
@tasks = filter (eq .done) @tasks
template:
textbox(sync: @newText, enter: :add, placeholder: placeholder)
button.activate-all(click: @tasks = map (.done = True) @tasks)
.item(
repeat<task>: filter (filterFn @filter) @tasks
dblClick: .editing = True
class<done>: .done
)
textbox(sync: .text, if: .editing)
.text(if: not .editing) {.text}
button.remove(click: :remove task) x
button.done(click: .done = true) done
button.clear-done(click: :clearDone)
.items-left {length <| filter (not << eq <| .done) @tasks}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment