UNPKG

1.25 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _immutable = require('immutable');
8
9var _authActions = require('../actions/authActions');
10
11var actions = _interopRequireWildcard(_authActions);
12
13function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
14
15/** Created by hhj on 7/13/16. */
16var InitialState = (0, _immutable.Record)({
17 isAuthenticationRequired: false,
18 token: null
19});
20
21var reducer = function reducer() {
22 var state = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
23 var action = arguments[1];
24
25 if (!(state instanceof InitialState)) return new InitialState(state);
26
27 switch (action.type) {
28 case actions.AUTHENTICATION_REQUIRED:
29 return state.set('isAuthenticationRequired', true);
30
31 case actions.LOGIN_SUCCESS:
32 return state.set('token', action.response.token).set('isAuthenticationRequired', false);
33
34 case actions.LOGOUT_SUCCESS:
35 return state.set('token', '');
36
37 default:
38 return state;
39 }
40};
41
42exports.default = reducer;
\No newline at end of file