Skip to content

Instantly share code, notes, and snippets.

@arqex
Last active September 19, 2015 15:18
Show Gist options
  • Save arqex/a21efc8fb9322947e959 to your computer and use it in GitHub Desktop.
Save arqex/a21efc8fb9322947e959 to your computer and use it in GitHub Desktop.
// Our input is something like
var TodoInput = React.createElement({
render: function(){
return <input value={ this.props.state.todoInput } onChange={ this.updateInput } />
},
updateInput: function(){
// We don't need to create a reaction for this,
// This is not a problem because the whole state will be
// updated and the whole app will be notified of this change
this.props.state.set({ todoInput: e.target.value }).now()
}
}
// It is great to control the value from outside,
// so we can reset the input when the todo is created
// Creation reaction:
freezer.on('todo:create', function( text ){
freezer.get()
.set({ todoInput: '' }) // Clear the input
.todos.push({
model: {title: text, completed: false},
ui: {state: 'ready', input: text}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment