Skip to content

Instantly share code, notes, and snippets.

@mweststrate
Created June 20, 2015 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mweststrate/2408f879252a33de322a to your computer and use it in GitHub Desktop.
Save mweststrate/2408f879252a33de322a to your computer and use it in GitHub Desktop.
shopping cart views
var CartView = React.createClass({
render: function() {
function renderEntry(entry) {
return (<CartEntryView entry={entry} cart={this.props.cart} key={entry.id} />);
}
return (<div>
<ul id="cart">{this.props.cart.entries.map(renderEntry)}</ul>
<div><b>Total: <span id="total">{this.props.cart.total}</span></b></div>
</div>)
}
});
var CartEntryView = React.createClass({
render: function() {
return (<li>
<button onClick={this.removeArticle}>&laquo;</button>
<span>{this.props.entry.article.name}</span>
<span>{this.props.entry.amount}</span>
</li>);
},
removeArticle: function() {
if (--this.props.entry.amount < 1)
this.props.cart.entries.splice(this.props.cart.entries.indexOf(this.props.entry), 1);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment