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:
Senad Uka
2015-05-14 06:21:49 +02:00
parent 49dd10acbc
commit 6453b1b241
22 changed files with 73 additions and 104 deletions

View File

@@ -106,7 +106,7 @@ var BySubCategoryStore = _.extend({}, EventEmitter.prototype, {
},
// Emit Change event
emitChange: function() {
console.log("Emmiting BySubCategory change!");
this.emit('change');
},

View File

@@ -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;

View File

@@ -45,7 +45,7 @@ var CategoryStore = _.extend({}, EventEmitter.prototype, {
},
// Emit Change event
emitChange: function() {
console.log("Emmiting Section change!");
this.emit('change');
},

View File

@@ -106,7 +106,7 @@ var InitializationStore = _.extend({}, EventEmitter.prototype, {
// Emit Change event
emitChange: function() {
console.log("InitializationStore change!");
this.emit('change');
},

View File

@@ -19,7 +19,7 @@ var getItemIdFromUrl = function() {
var url = document.URL;
var itemIdRegex = /artikal\/(\d+)\//g;
var match = itemIdRegex.exec(url);
console.log(match);
return match[1];
};
@@ -95,7 +95,6 @@ var ItemWithDetailsStore = _.extend({}, EventEmitter.prototype, {
// Emit Change event
emitChange: function() {
console.log("Emitting change!");
this.emit('change');
},

View File

@@ -33,7 +33,7 @@ var getItemIdFromUrl = function() {
var url = document.URL;
var itemIdRegex = /artikal\/(\d+)\//g;
var match = itemIdRegex.exec(url);
console.log(match);
return match[1];
};
@@ -80,7 +80,7 @@ var fetchItemsByCategory = function(categoryId, offset, limit, query) {
};
var fetchBestSellingItemsForSection = function(sectionId) {
console.log('getting section', sectionId);
var items = _bestSellingForSection;
items.setClassificationType(1);
items.setClassificationId(sectionId);
@@ -96,7 +96,7 @@ var fetchBestSellingItemsForSection = function(sectionId) {
var fetchBestSellingItemsForGroup = function(groupId) {
console.log('getting group', groupId);
var items = _bestSellingForGroup;
items.setClassificationType(4);
items.setClassificationId(groupId);
@@ -138,7 +138,7 @@ var ItemStore = _.extend({}, EventEmitter.prototype, {
// Emit Change event
emitChange: function() {
console.log("Emitting change!");
this.emit('change');
},

View File

@@ -38,7 +38,6 @@ var MenuItemStore = _.extend({}, EventEmitter.prototype, {
},
// Emit Change event
emitChange: function() {
console.log("Emmiting MenuItemStore change!");
this.emit('change');
},

View File

@@ -9,7 +9,6 @@ var _ = require('underscore');
var getGroupIdFromUrl = function() {
console.log("yeee" , match);
// ugly but it seems to me that
// router does not want to expose its
// state (for phylosophical reasons)
@@ -31,7 +30,6 @@ var NavigationStore = _.extend({}, EventEmitter.prototype, {
// Emit Change event
emitChange: function() {
console.log("NavigationStore change!");
this.emit('change');
},

View File

@@ -46,7 +46,7 @@ var SearchStore = _.extend({}, EventEmitter.prototype, {
},
// Emit Change event
emitChange: function() {
console.log("SearchStore change!");
this.emit('change');
},

View File

@@ -30,7 +30,7 @@ var loadSectionDetails = function(sectionId) {
section.fetch({
success: function() {
_sectionDetails = section;
console.log('section details', _sectionDetails);
SectionStore.emitChange();
}
});
@@ -53,7 +53,7 @@ var SectionStore = _.extend({}, EventEmitter.prototype, {
},
// Emit Change event
emitChange: function() {
console.log("Emmiting Section change!");
this.emit('change');
},

View File

@@ -23,8 +23,6 @@ var handleRegistrationFailure = function(error) {
error: error
};
console.log('ERROR JE: ', error);
};
var handleLoginSuccess = function(user) {
@@ -92,7 +90,6 @@ var UserStore = _.extend({}, EventEmitter.prototype, {
},
// Emit Change event
emitChange: function() {
console.log("Emmiting Section change!");
this.emit('change');
},