var React = require('react');
var CartStore = require('../../stores/cartStore.js');
var CartActions = require('../../actions/cartActions.js');
var countStyle = {
width: '100%'
};
var AddToCart = React.createClass({
render: function() {
return (
);
},
// Add change listeners to stores
componentDidMount: function() {
CartActions.load();
CartStore.addChangeListener(this._onChange);
},
getInitialState: function() {
return CartStore.getStateFor(this.props.itemId)
},
_onChange: function () {
if (this.isMounted()) {
this.setState(CartStore.getStateFor(this.props.itemId));
}
},
_onIncreaseClick: function () {
CartActions.addItem(this.props.itemId);
},
_onDecreaseClick: function () {
CartActions.takeItemOut(this.props.itemId);
}
});
module.exports = AddToCart;