2016-03-18 11:51:22 -04:00
|
|
|
var combineReducers = require('redux').combineReducers;
|
|
|
|
|
|
|
|
var actionTypes = require('./actions.js').types;
|
|
|
|
|
|
|
|
|
|
|
|
var sessionReducer = function (state, action) {
|
|
|
|
// Reducer for handling changes to session state
|
|
|
|
if (typeof state === 'undefined') {
|
|
|
|
state = {};
|
|
|
|
}
|
|
|
|
switch (action.type) {
|
|
|
|
case actionTypes.SET_SESSION:
|
|
|
|
return action.session;
|
|
|
|
case actionTypes.SET_SESSION_ERROR:
|
|
|
|
// TODO: do something with action.error
|
|
|
|
return state;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-22 14:43:07 -04:00
|
|
|
var tokenReducer = function (state, action) {
|
|
|
|
// Reducer for updating the api token
|
|
|
|
if (typeof state === 'undefined') {
|
|
|
|
state = '';
|
|
|
|
}
|
|
|
|
switch (action.type) {
|
|
|
|
case actionTypes.SET_TOKEN:
|
|
|
|
return action.token;
|
|
|
|
case actionTypes.SET_TOKEN_ERROR:
|
|
|
|
// TODO: do something with the error
|
|
|
|
return state;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-18 11:51:22 -04:00
|
|
|
var appReducer = combineReducers({
|
2016-03-22 14:43:07 -04:00
|
|
|
session: sessionReducer,
|
|
|
|
token: tokenReducer
|
2016-03-18 11:51:22 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = appReducer;
|