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:
@@ -24,8 +24,12 @@ var _deliveryCosts = new Place({
|
||||
postalCode: _deliveryDestination.get('place')
|
||||
})
|
||||
|
||||
var _cartDataLoadCalled = false;
|
||||
|
||||
|
||||
var loadCart = function() {
|
||||
|
||||
states = {};
|
||||
_itemsInCart.fetch({
|
||||
success: function() {
|
||||
states = {}
|
||||
@@ -50,8 +54,10 @@ var loadCart = function() {
|
||||
CartActions.dataLoaded();
|
||||
}
|
||||
});
|
||||
|
||||
_cartDataLoadCalled = true;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
var fetchPlace = function() {
|
||||
@@ -71,22 +77,12 @@ var saveCartStateForItem = function(itemId) {
|
||||
var item = CartStore.getStateFor(itemId);
|
||||
item.save({
|
||||
success: function() {
|
||||
CartActions.dataLoaded();
|
||||
loadCart();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var addItem = function(itemId) {
|
||||
|
||||
var state = states[itemId] || new ItemInCart({
|
||||
item_id: itemId,
|
||||
count: 0
|
||||
})
|
||||
state.set('count', state.get('count') + 1);
|
||||
states[itemId] = state;
|
||||
saveCartStateForItem(itemId);
|
||||
|
||||
};
|
||||
/* need it for delete - will delete it later
|
||||
|
||||
var takeItemOut = function(itemId) {
|
||||
|
||||
@@ -101,15 +97,20 @@ var takeItemOut = function(itemId) {
|
||||
saveCartStateForItem(itemId);
|
||||
};
|
||||
|
||||
var setItemCount = function(itemId, count) {
|
||||
*/
|
||||
|
||||
var setItemCount = function(item, count) {
|
||||
|
||||
var itemId = item.get('id');
|
||||
var state = states[itemId] || new ItemInCart({
|
||||
item_id: itemId,
|
||||
count: 0
|
||||
})
|
||||
console.log("Old state", state.get('count'));
|
||||
|
||||
_itemsForDisplay.add(item);
|
||||
|
||||
state.set('count', state.get('count') + count);
|
||||
console.log("New state", state.get('count'));
|
||||
|
||||
states[itemId] = state;
|
||||
saveCartStateForItem(itemId);
|
||||
}
|
||||
@@ -125,7 +126,7 @@ var changeDeliveryDestinationProperty = function(property, value) {
|
||||
|
||||
|
||||
var confirmOrder = function() {
|
||||
console.log("confirming");
|
||||
|
||||
var oc = new OrderConfirmation({
|
||||
hamo: 'meho'
|
||||
});
|
||||
@@ -133,7 +134,7 @@ var confirmOrder = function() {
|
||||
b: 'b'
|
||||
}, {
|
||||
success: function() {
|
||||
console.log("done");
|
||||
|
||||
NavigationActions.goToThankYou();
|
||||
loadCart();
|
||||
}
|
||||
@@ -142,10 +143,9 @@ var confirmOrder = function() {
|
||||
|
||||
|
||||
var saveDeliveryDestination = function() {
|
||||
console.log("saving delivery destination");
|
||||
_deliveryDestination.save(null, {
|
||||
success: function() {
|
||||
console.log("saved delivery destination");
|
||||
|
||||
confirmOrder();
|
||||
}
|
||||
})
|
||||
@@ -197,6 +197,10 @@ var isDeliveryDestinationValid = function() {
|
||||
// Extend CartStore with EventEmitter to add eventing capabilities
|
||||
var CartStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
dataStartedLoading: function() {
|
||||
return _cartDataLoadCalled;
|
||||
},
|
||||
|
||||
getStateFor: function(itemId) {
|
||||
|
||||
var state = states[itemId] || new ItemInCart({
|
||||
@@ -234,7 +238,6 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emitting cart change!");
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
@@ -288,7 +291,7 @@ AppDispatcher.register(function(payload) {
|
||||
saveDeliveryDestination();
|
||||
break;
|
||||
case CartConstants.SET_ITEM_COUNT:
|
||||
setItemCount(action.itemId, action.count);
|
||||
setItemCount(action.item, action.count);
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user