Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

85 lines (64 sloc) 2.24 KB
derby = require 'derby'
{get, view, ready} = derby.createApp module
derby.use(require '../../ui')
view.fn 'noItems',
get: (list) -> !list.length unless list is undefined
set: ->
view.fn 'oneItem',
get: (list) -> list.length == 1 unless list is undefined
# Redirect the visitor to a random todo list
get '/', (page) ->
page.redirect '/' + parseInt(Math.random() * 1e9).toString(36)
# Sets up the model, the reactive function for stats and renders the todo list
get '/:groupName', (page, model, {groupName}) ->
model.query('todos').forGroup(groupName).subscribe ->
model.set '_groupName', groupName
model.ref '_list.all', model.filter('todos')
model.ref '_list.completed', model.filter('todos')
model.ref '', model.filter('todos')
model.set '_filter', 'all'
model.ref '_list.shown', '_list', '_filter'
# Transitional route for enabling a filter
get from: '/:groupName', to: '/:groupName/:filterName',
forward: (model, {filterName}) ->
model.set '_filter', filterName
back: (model, params) ->
model.set '_filter', 'all'
get from: '/:groupName/:filterName', to: '/:groupName/:filterName',
forward: (model, {filterName}) ->
model.set '_filter', filterName
ready (model) ->
todos = 'todos'
newTodo = '_newTodo'
exports.add = ->
# Don't add a blank todo
text = newTodo.get().trim()
newTodo.set ''
return unless text
todos.add text: text, group: model.get('_groupName')
exports.del = (e, el) ->
# Derby extends to support creation from DOM nodes
exports.clearCompleted = ->
for {id} in model.get('_list.completed')
todos.del id
exports.clickToggleAll = ->
value = !!model.get('')
for {id} in model.get('_list.all')
todos.set id + '.completed', value
exports.submitEdit = (e, el) ->
exports.startEdit = (e, el) ->
item =
item.set '_editing', true
exports.endEdit = (e, el) ->
item =
item.set '_editing', false
if item.get('text').trim() == ''
todos.del item.get('id')
Jump to Line
Something went wrong with that request. Please try again.