Skip to content

Instantly share code, notes, and snippets.

@arqex
Last active May 14, 2017 10:44
Show Gist options
  • Save arqex/e7ac2394971176b7b72d106bbb01a437 to your computer and use it in GitHub Desktop.
Save arqex/e7ac2394971176b7b72d106bbb01a437 to your computer and use it in GitHub Desktop.
Events in Freezer
class UserCreator extends React.Component {
render(){
// This component will let us create an user by name
return (
<div className="userCreator">
<input name="name" onChange={ e => this.setState({name}) } />
<button onClick={ () => this.save() } />
</div>
);
}
save(){
freezer.emit( 'user:create', this.state.name );
}
}
// In a different file we can handle the state update
// This is the `user:create reaction
freezer.on('user:create', name => {
var id = 100;
freezer.get().users.set(id, {id: id, name: name});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment