loading best selling items for sections
This commit is contained in:
@@ -7,7 +7,8 @@ var _ = require('underscore');
|
||||
|
||||
// Define initial data points
|
||||
var _items = new ItemCollection(),
|
||||
_itemWithDetails = new ItemWithDetails();
|
||||
_itemWithDetails = new ItemWithDetails(),
|
||||
_bestSellingForSection = new ItemCollection();
|
||||
|
||||
|
||||
var loadItemsForFrontpage = function() {
|
||||
@@ -49,10 +50,30 @@ var fetchItemWithDetails = function() {
|
||||
}
|
||||
}
|
||||
|
||||
var fetchBestSellingItemsForSection = function(sectionId) {
|
||||
console.log('getting section', sectionId);
|
||||
var items = _bestSellingForSection;
|
||||
items.setClassificationType(1);
|
||||
items.setClassificationId(sectionId);
|
||||
items.setLimit(30);
|
||||
items.setOffset(0);
|
||||
|
||||
|
||||
items.fetch({
|
||||
success: function() {
|
||||
ItemStore.emitChange();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Extend ItemStore with EventEmitter to add eventing capabilities
|
||||
var ItemStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
getBestSellingForSection: function() {
|
||||
|
||||
return _bestSellingForSection;
|
||||
},
|
||||
// item with details
|
||||
getLoadedItemWithDetails: function() {
|
||||
return _itemWithDetails;
|
||||
@@ -94,6 +115,9 @@ AppDispatcher.register(function(payload) {
|
||||
fetchItemWithDetails();
|
||||
break;
|
||||
|
||||
case ItemConstants.LOAD_BSI_FOR_SECTION:
|
||||
fetchBestSellingItemsForSection(action.sectionId);
|
||||
break;
|
||||
|
||||
case ItemConstants.LOAD_FOR_FRONTPAGE:
|
||||
loadItemsForFrontpage();
|
||||
@@ -109,4 +133,4 @@ AppDispatcher.register(function(payload) {
|
||||
|
||||
});
|
||||
|
||||
module.exports = ItemStore;
|
||||
module.exports = ItemStore;
|
||||
|
||||
@@ -1,27 +1,38 @@
|
||||
var AppDispatcher = require('../dispatcher/appDispatcher');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var SectionCollection = require('../models/sectionCollection');
|
||||
var Section = require('../models/section');
|
||||
var SectionConstants = require('../constants/sectionConstants');
|
||||
var _ = require('underscore');
|
||||
|
||||
|
||||
var _sectionDetails = new Section();
|
||||
var sectionState = {
|
||||
sections : [],
|
||||
hoveredSection : ''
|
||||
sections : [],
|
||||
hoveredSection : ''
|
||||
};
|
||||
|
||||
|
||||
var loadSections = function() {
|
||||
var sections = new SectionCollection();
|
||||
sections.fetch({success: function() {
|
||||
sectionState.sections = sections.models;
|
||||
// change will be called automatically when
|
||||
// action is run but we need to emit it again
|
||||
// when the data arive
|
||||
// it's a bit "unfluxy" but convenient.
|
||||
// "true philosophy" would be to run another "data arrived" action
|
||||
SectionStore.emitChange();
|
||||
}});
|
||||
var sections = new SectionCollection();
|
||||
sections.fetch({success: function() {
|
||||
sectionState.sections = sections.models;
|
||||
// change will be called automatically when
|
||||
// action is run but we need to emit it again
|
||||
// when the data arive
|
||||
// it's a bit "unfluxy" but convenient.
|
||||
// "true philosophy" would be to run another "data arrived" action
|
||||
SectionStore.emitChange();
|
||||
}});
|
||||
};
|
||||
|
||||
var loadSectionDetails = function(sectionId) {
|
||||
var section = new Section({id : sectionId});
|
||||
section.fetch({
|
||||
success: function() {
|
||||
_sectionDetails = section;
|
||||
SectionStore.emitChange();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var setHovered = function(id) {
|
||||
@@ -36,23 +47,24 @@ var SectionStore = _.extend({}, EventEmitter.prototype, {
|
||||
getState: function() {
|
||||
return sectionState;
|
||||
},
|
||||
getSectionDetails: function() {
|
||||
return _sectionDetails;
|
||||
},
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emmiting Section change!");
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("Emmiting Section change!");
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
// Add change listener
|
||||
addChangeListener: function(callback) {
|
||||
this.on('change', callback);
|
||||
},
|
||||
|
||||
// Remove change listener
|
||||
removeChangeListener: function(callback) {
|
||||
this.removeListener('change', callback);
|
||||
}
|
||||
// Add change listener
|
||||
addChangeListener: function(callback) {
|
||||
this.on('change', callback);
|
||||
},
|
||||
|
||||
// Remove change listener
|
||||
removeChangeListener: function(callback) {
|
||||
this.removeListener('change', callback);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -76,6 +88,10 @@ AppDispatcher.register(function(payload) {
|
||||
setHovered('');
|
||||
break;
|
||||
|
||||
case SectionConstants.LOAD_SECTION_DETAILS:
|
||||
loadSectionDetails(action.sectionId);
|
||||
break;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user