Skip to content

Commit 65fc7ec

Browse files
committed
fix formatting
1 parent 0a69620 commit 65fc7ec

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

examples/todo/todo.coffee

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ createStorage = (id) ->
33
load: -> JSON.parse(localStorage.getItem(this._id) or '[]')
44
save: (x) -> localStorage.setItem this._id, JSON.stringify(x)
55

6+
67
createActions = ->
78
to_hash ([name, new Bacon.Bus()] for name in \
89
['creates', 'destroys', 'edits', 'toggles', 'megatoggles', 'clears'])
910

11+
1012
createModel = (initialTodos, actions) ->
1113
mutators =
1214
append: (newTodo) -> (todos) -> todos.concat [newTodo]
@@ -20,7 +22,7 @@ createModel = (initialTodos, actions) ->
2022
_.defaults {completed}, t
2123

2224
{creates, destroys, edits, toggles, megatoggles, clears} = actions
23-
# thanks to Juha Paananen for the stream of functions pattern!
25+
# thanks to Juha Paananen for the stream-of-functions pattern!
2426
mutations = creates.map(mutators.create)
2527
.merge(destroys.map(mutators.delete))
2628
.merge(toggles.merge(edits).map(mutators.update))
@@ -32,34 +34,36 @@ createModel = (initialTodos, actions) ->
3234
completedTodos = allTodos.map (todos) -> _.where todos, completed: true
3335
{allTodos, activeTodos, completedTodos}
3436

37+
3538
createView = (model, actions, hash) ->
36-
rendactive Handlebars.compile($("#app").html()), (h) ->
39+
rendactive Handlebars.compile($('#app').html()), (h) ->
3740
title = h.inputValue('#new-todo').map((val) -> val.trim())
38-
h.enters("#new-todo").onValue -> $("#new-todo").val('')
41+
h.enters('#new-todo').onValue -> $('#new-todo').val('')
3942

4043
# convert ui events into actions
4144
{creates, destroys, edits, toggles, megatoggles, clears} = actions
42-
creates.plug h.enters("#new-todo").map(title).filter(_.identity)
43-
destroys.plug h.ids("click [data-action=delete]")
44-
edits.plug h.enters(".edit").merge(h.blurs(".edit")).map (e) ->
45+
creates.plug h.enters('#new-todo').map(title).filter(_.identity)
46+
destroys.plug h.ids('click [data-action=delete]')
47+
edits.plug h.enters('.edit').merge(h.blurs('.edit')).map (e) ->
4548
id: $(e.target).data('id')
4649
changes: {title: $(e.target).val().trim()}
4750
destroys.plug edits.filter(({changes}) -> !changes.title).map(({id}) -> id)
48-
toggles.plug h.changes("[data-action=toggle]").map (e) ->
51+
toggles.plug h.changes('[data-action=toggle]').map (e) ->
4952
id: $(e.target).data('id')
50-
changes: {completed: $(e.target).is(":checked")}
51-
megatoggles.plug h.checkboxBooleans("#toggle-all")
52-
clears.plug h.clicks("#clear-completed")
53+
changes: {completed: $(e.target).is(':checked')}
54+
megatoggles.plug h.checkboxBooleans('#toggle-all')
55+
clears.plug h.clicks('#clear-completed')
5356

54-
editingId = h.ids("dblclick label").merge(edits.map(null)).toProperty(null)
55-
h.valueAfterRender editingId, (id) -> $("#edit-#{id}").focus()
57+
editingId = h.ids('dblclick label').merge(edits.map(null)).toProperty(null)
58+
h.valueAfterRender editingId, (id) -> $('#edit-#{id}').focus()
5659

5760
{allTodos, activeTodos, completedTodos} = model
5861
selectedTodos = hash.decode
5962
'#/': allTodos, '#/active': activeTodos, '#/completed': completedTodos
6063

6164
{allTodos, completedTodos, activeTodos, selectedTodos, editingId}
6265

66+
6367
createApplication = ->
6468
hash = Bacon.UI.hash '#/'
6569
storage = createStorage('todos-rendactive')
@@ -71,5 +75,6 @@ createApplication = ->
7175
model.allTodos.onValue storage.save
7276
{model, view, actions}
7377

78+
7479
app = createApplication()
7580
$('body').append(app.view.fragment)

0 commit comments

Comments
 (0)