fixed problem with multiple carts and a whole load of problems with crazy delivery destination logic / if I didn't write it i would have thought it was written by a drug abuser during high
This commit is contained in:
69
front-ui/app/stores/initializationStore.js
Normal file
69
front-ui/app/stores/initializationStore.js
Normal file
@@ -0,0 +1,69 @@
|
||||
var AppDispatcher = require('../dispatcher/appDispatcher');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Cart = require('../models/cart');
|
||||
|
||||
var InitializationConstants = require('../constants/initializationConstants')
|
||||
var _ = require('underscore');
|
||||
|
||||
|
||||
var state = {
|
||||
isEverythingReadyToStartTheShow: false
|
||||
}
|
||||
|
||||
var initializeTheShop = function () {
|
||||
// for now only guarantee that cart is created
|
||||
var cart = new Cart();
|
||||
cart.save(null, {
|
||||
success: function () {
|
||||
state.isEverythingReadyToStartTheShow = true;
|
||||
InitializationStore.emitChange();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Extend ItemStore with EventEmitter to add eventing capabilities
|
||||
var InitializationStore = _.extend({}, EventEmitter.prototype, {
|
||||
|
||||
getState: function() {
|
||||
return state;
|
||||
},
|
||||
|
||||
// Emit Change event
|
||||
emitChange: function() {
|
||||
console.log("InitializationStore change!");
|
||||
this.emit('change');
|
||||
},
|
||||
|
||||
// Add change listener
|
||||
addChangeListener: function(callback) {
|
||||
this.on('change', callback);
|
||||
},
|
||||
|
||||
// Remove change listener
|
||||
removeChangeListener: function(callback) {
|
||||
this.removeListener('change', callback);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Register callback with AppDispatcher
|
||||
InitializationStore.dispatchToken = AppDispatcher.register(function(payload) {
|
||||
var action = payload.action;
|
||||
|
||||
switch (action.actionType) {
|
||||
|
||||
case InitializationConstants.INITIALIZE:
|
||||
initializeTheShop();
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
// If action was responded to, emit change event
|
||||
InitializationStore.emitChange();
|
||||
return true;
|
||||
|
||||
});
|
||||
|
||||
module.exports = InitializationStore;
|
||||
Reference in New Issue
Block a user