Skip to content

Instantly share code, notes, and snippets.

@crullian
Created September 17, 2016 17:20
Show Gist options
  • Save crullian/4d0790d052ef679361f80edc4fa15ce4 to your computer and use it in GitHub Desktop.
Save crullian/4d0790d052ef679361f80edc4fa15ce4 to your computer and use it in GitHub Desktop.
Comparing React and Ember
var LikeButton = Ember.View.extend({
init: function() {
this._super()
this.set('liked', false};
},
likedText: function(){
return(this.get('liked') ? 'like' : 'unlike')
}.property('liked'),
click: function(event) {
this.set('liked', !this.get('liked')); // or this.toggleProperty('liked')
},
template: Ember.Handlebars.compile("
<p>
You {{likedText}} this. Click to toggle.
</p>
")
});
LikeButton.create().appendTo('#example')
/** @jsx React.DOM */
var LikeButton = React.createClass({
getInitialState: function() {
return {liked: false};
},
handleClick: function(event) {
this.setState({liked: !this.state.liked});
},
render: function() {
var text = this.state.liked ? 'like' : 'unlike';
return (
<p onClick={this.handleClick}>
You {text} this. Click to toggle.
</p>
);
}
});
React.renderComponent(
<LikeButton />,
document.getElementById('example')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment