1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _immutable = require('immutable');
|
8 |
|
9 | var _authActions = require('../actions/authActions');
|
10 |
|
11 | var actions = _interopRequireWildcard(_authActions);
|
12 |
|
13 | function _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 |
|
16 | var InitialState = (0, _immutable.Record)({
|
17 | isAuthenticationRequired: false,
|
18 | token: null
|
19 | });
|
20 |
|
21 | var 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 |
|
42 | exports.default = reducer; |
\ | No newline at end of file |