UNPKG

@natlibfi/melinda-merge-ui-commons

Version:
81 lines (71 loc) 2.65 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = session; exports.createSessionStart = createSessionStart; exports.createSessionError = createSessionError; exports.createSessionSuccess = createSessionSuccess; exports.validateSessionStart = validateSessionStart; var _immutable = require('immutable'); var _actionTypeConstants = require('../constants/action-type-constants'); /** * * @licstart The following is the entire license notice for the JavaScript code in this file. * * Common modules for Melinda UI applications * * Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland) * * This file is part of melinda-ui-commons * * melinda-ui-commons program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * melinda-ui-commons is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * @licend The above is the entire license notice * for the JavaScript code in this file. * */ var INITIAL_STATE = (0, _immutable.Map)({ state: 'NO_SESSION', userinfo: undefined, error: undefined }); function session() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INITIAL_STATE; var action = arguments[1]; switch (action.type) { case _actionTypeConstants.CREATE_SESSION_START: return createSessionStart(state); case _actionTypeConstants.CREATE_SESSION_ERROR: return createSessionError(state, action.error); case _actionTypeConstants.CREATE_SESSION_SUCCESS: return createSessionSuccess(state, action.userinfo); case _actionTypeConstants.VALIDATE_SESSION_START: return validateSessionStart(state); } return state; } function createSessionStart(state) { return state.set('state', 'SIGNIN_ONGOING'); } function createSessionError(state, error) { return state.set('state', 'SIGNIN_ERROR').set('error', error); } function createSessionSuccess(state, userinfo) { return state.set('state', 'SIGNIN_OK').set('userinfo', userinfo); } function validateSessionStart(state) { return state.set('state', 'VALIDATION_ONGOING'); } //# sourceMappingURL=session-reducer.js.map