Last active
September 19, 2015 15:18
-
-
Save arqex/a21efc8fb9322947e959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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