Skip to content

Instantly share code, notes, and snippets.

@withinboredom
Last active August 29, 2015 14:18
Show Gist options
  • Save withinboredom/09e83ef85aa209d7765a to your computer and use it in GitHub Desktop.
Save withinboredom/09e83ef85aa209d7765a to your computer and use it in GitHub Desktop.
someday, you can compile this
gsd.todoList.todo <- aggregate
thingTodo <- value
done <- value
deleted <- value
markedComplete <- event
guard:
if @done != false
emit Failure
else
emit Success
mutate:
@done = true
test:
'can mark complete':
@done = false
emit markedComplete
waitFor Success =>
assert @done, true
'cannot mark complete if already complete':
@done = true
emit markedComplete
waitFor Failure =>
assert @done, true
markedIncomplete <- event
guard:
if @done == true
emit Failure
else
emit Success
mutate:
@done = false
test:
'can mark incomplete':
@done = true
waitFor Success =>
assert @done, false
'cannot mark incomplete twice':
@done = false
emit markedIncomplete
waitFor Failure =>
assert @done, false
changedThing <- event (newThing)
guard:
if %newThing canBe String
emit Success
else
emit Failure
mutate:
@thingTodo = %newThing as String
test:
'able to change things':
@done = false
emit changedThing 'stuff'
waitFor Success =>
@thingTodo = 'stuff'
unDeletedTodo <- event
mutate:
@deleted = false
test:
'able to undelete an event':
@deleted = true
emit unDeletedTodo =>
assert @deleted, false
addedNewTodo <- event (newThing)
guard:
sameAs gsd.todoList.todo.changedThing.guard
mutate:
emit markedIncomplete
emit unDeletedTodo
emit changedThing %newThing
test:
'able to create new todo':
emit addedNewTodo 'stuff'
waitFor markedIncomplete.[Success, Failure], unDeletedTodo, changedThing.Success =>
assert @deleted, false
assert @done, false
assert @thingTodo, 'stuff'
deleteTodo <- event
guard:
emit Success
mutate:
@deleted = true
test:
'able to delete todo':
emit addedNewTodo 'stuff'
waitFor addedNewTodo.Success =>
emit deleteTodo
waitFor Success =>
assert @deleted, true
gsd.todoList.todos <- aggregate
myList <- container <- todo
activeItems <- container
read:
return filter @myList, (item) ->
if item.done
return false
return true
itemsLeft <- value
read:
return @activeItems.length
completedItems <- container
read:
return filter @myList, (item) ->
if item.done
return true
return false
addedNewTodo <- event (newThing)
guard:
emit Success
mutate:
@list.Add %
test:
'can add new todo':
emit addedNewTodo
waitFor gsd.todoList.todo.addedNewTodo.Success, gsd.todoList.todos.addedNewTodo.Success =>
assert @myList.length, 1
deletedTodo <- event
guard:
todo = findAll @list, %
if todo.length > 0
emit Success
else
emit Failure
mutate:
@list.remove %
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment