Skip to content

Instantly share code, notes, and snippets.

@excid3
Created March 29, 2015 04:32
Show Gist options
  • Save excid3/57a4e6e417d0682af7f8 to your computer and use it in GitHub Desktop.
Save excid3/57a4e6e417d0682af7f8 to your computer and use it in GitHub Desktop.
@TodoList = React.createClass
render: ->
`<ul>
{this.props.todos.map(
function(todo, index){
return (<TodoItem key={index} id={todo.id} description={todo.description} completed_at={todo.completed_at} />)
}, this)
}
</ul>`
@TodoItem = React.createClass
getInitialState: ->
{completed: this.props.completed_at?}
handleChange: ->
$.ajax(
method: "PATCH"
url: "/todos/#{this.props.id}/complete"
success: =>
this.setState completed: !this.state.completed
)
render: ->
`<li>
<label>
<input type="checkbox" checked={this.state.completed} onChange={this.handleChange} />{this.props.description}
</label>
</li>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment