Created
September 17, 2016 17:20
-
-
Save crullian/4d0790d052ef679361f80edc4fa15ce4 to your computer and use it in GitHub Desktop.
Comparing React and Ember
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
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') |
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
/** @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