mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-12-02 11:59:07 -05:00
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
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;
|
|
}
|
|
};
|
|
|
|
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;
|
|
}
|
|
};
|
|
|
|
var appReducer = combineReducers({
|
|
session: sessionReducer,
|
|
token: tokenReducer
|
|
});
|
|
|
|
module.exports = appReducer;
|