Skip to content

Commit

Permalink
モデル変更したら ビューに通知して再描画するように変更した
Browse files Browse the repository at this point in the history
  • Loading branch information
haru01 committed May 2, 2012
1 parent cb119f7 commit 8e74339
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions views/index.jade
Expand Up @@ -23,31 +23,31 @@ div#board
initialize: ->
_.bindAll(@, 'render', 'next', 'initCase', 'birth')
@model = new Space([[0, 0, 0],
[0, 0 ,0],
[0, 0 ,0]])
@model = new Backbone.Model(
space: new Space([[0, 0, 0],
[0, 0 ,0],
[0, 0 ,0]]))
@model.on('change:space', @render, @)
@render()
render: ->
$("#space-board").empty();
$("#space-board").append(this.template());
$("#space-board").append(@template());
next: ->
@model = @model.nextTime()
@render()
@model.set 'space', @model.get('space').nextTime()
initCase: ->
name = $('#init-case option:selected').val()
this[name]()
@render()
birth: ->
@model = new Space([[1, 1, 0],
[1, 0 ,0],
[0, 0 ,0]])
@model.set 'space', new Space [[1, 1, 0],
[1, 0 ,0],
[0, 0 ,0]]
template: ->
#TODO extract
cells = this.model.cells
cells = @model.get('space').cells
table = $("<table>")
for row, y in cells
tr = $("<tr>")
Expand Down

0 comments on commit 8e74339

Please sign in to comment.