All files / src/store login-reducer.ts

80% Statements 4/5
66.66% Branches 2/3
100% Functions 1/1
80% Lines 4/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                          1x                     1x       1x     1x                  
import {Action, LOGIN, LOGIN_USERNAME} from "../type";
 
 
/**
 * The login state stored
 */
export type LoginState = {
    username: string
}
 
/**
 * Initial state
 */
export const initialState: LoginState = {
    username: ''
}
 
 
/**
 * Login reducer
 * @param state the current application state
 * @param action the action dispatched
 * @return the modified {@link LoginState}
 */
const loginReducer = (
    state: LoginState = initialState,
    action: Action
): LoginState => {
    switch (action.type) {
        case LOGIN:
        case LOGIN_USERNAME:
            return {
                ...state,
                username: action.payload
            }
    }
    return state
}
 
export default loginReducer