fixed bug with amount not updating / solved double dispatch problem with cartAction.load / removed all console.log calls - it became too chatty / add them as needed
This commit is contained in:
@@ -35,12 +35,15 @@ var AddToCart = React.createClass({
|
||||
// Add change listeners to stores
|
||||
componentDidMount: function() {
|
||||
CartStore.addChangeListener(this._onChange);
|
||||
CartActions.load();
|
||||
|
||||
if(!CartStore.dataStartedLoading()) {
|
||||
CartActions.load();
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
getInitialState: function() {
|
||||
var itemInCart = CartStore.getStateFor(this.props.itemId);
|
||||
var itemInCart = CartStore.getStateFor(this.props.item.get('id'));
|
||||
return {
|
||||
item: itemInCart,
|
||||
count: 0
|
||||
@@ -50,13 +53,13 @@ var AddToCart = React.createClass({
|
||||
|
||||
_onChange: function () {
|
||||
if (this.isMounted()) {
|
||||
var item = CartStore.getStateFor(this.props.itemId);
|
||||
var item = CartStore.getStateFor(this.props.item.get('id'));
|
||||
this.setState({ item: item, count: 0 });
|
||||
}
|
||||
},
|
||||
|
||||
_onIncreaseClick: function () {
|
||||
//CartActions.addItem(this.props.itemId);
|
||||
|
||||
if (this.state.count < Globals.MaxNumberOfItemsToBeAdded ) {
|
||||
this.state.count = this.state.count + 1;
|
||||
this.setState(this.state);
|
||||
@@ -64,7 +67,7 @@ var AddToCart = React.createClass({
|
||||
},
|
||||
|
||||
_onDecreaseClick: function () {
|
||||
// CartActions.takeItemOut(this.props.itemId);
|
||||
|
||||
if (this.state.count > 0) {
|
||||
this.state.count = this.state.count - 1;
|
||||
this.setState(this.state);
|
||||
@@ -72,7 +75,7 @@ var AddToCart = React.createClass({
|
||||
},
|
||||
|
||||
_addToCartClick: function () {
|
||||
CartActions.setItemCount(this.props.itemId, this.state.count);
|
||||
CartActions.setItemCount(this.props.item, this.state.count);
|
||||
},
|
||||
|
||||
componentWillUnmount: function () {
|
||||
|
||||
Reference in New Issue
Block a user