Skip to content

Instantly share code, notes, and snippets.

@mushfiqweb
Created April 24, 2017 14:35
Show Gist options
  • Save mushfiqweb/e3934669d7d2b9a7dd9588272e81888f to your computer and use it in GitHub Desktop.
Save mushfiqweb/e3934669d7d2b9a7dd9588272e81888f 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