Files
optolith-client/js/stores/ELStore.js
T
Lukas Obermann 7c229853e7 Updated babel, fixing data flow in ListStore
Transferring all Actions to ListStore to regain unidirectional data flow for all stores. Other Stores only will store section-specific data e.g. filters.
2016-11-02 02:23:02 +01:00

85 lines
1.2 KiB
JavaScript

import AppDispatcher from '../dispatcher/AppDispatcher';
import EventEmitter from 'events';
import ActionTypes from '../constants/ActionTypes';
// EL = Experience Level
var _el = {};
var _start = 'EL_0';
function _init(el) {
_el = el;
}
function _update(el) {
_start = el;
}
function _clear() {
_start = 'EL_0';
}
var ELStore = Object.assign({}, EventEmitter.prototype, {
emitChange: function() {
this.emit('change');
},
addChangeListener: function(callback) {
this.on('change', callback);
},
removeChangeListener: function(callback) {
this.removeListener('change', callback);
},
get: function(id) {
return _el[id];
},
getAll: function() {
return _el;
},
getStartID: function() {
return _start;
},
getStart: function() {
return this.get(this.getStartID());
}
});
ELStore.dispatchToken = AppDispatcher.register( function( payload ) {
switch( payload.actionType ) {
case ActionTypes.CREATE_NEW_HERO:
_update(payload.el);
break;
case ActionTypes.CLEAR_HERO:
_clear();
break;
case ActionTypes.RECEIVE_HERO:
_update(payload.el);
break;
case ActionTypes.RECEIVE_RAW_LISTS:
_init(payload.el);
break;
default:
return true;
}
ELStore.emitChange();
return true;
});
export default ELStore;