import { SIGN_OFF } from './../auth/store/auth.actions';
import { AuthState, authReducers } from "../auth/store/auth.reducers";
import { ActionReducerMap, Action } from "@ngrx/store";

export interface AppState{
    authState: AuthState;
}

export const reducers: ActionReducerMap<AppState> = {
    authState: authReducers,
};

export function clearState(reducer: any) {
    return function (state: any, action: Action) {
        if (action.type === SIGN_OFF) {
            if(state.authState.loginTimeout)
                clearTimeout(state.authState.loginTimeout);
            state = undefined;
        }
        return reducer(state, action);
    };
}