history.ts 619 Bytes
Newer Older
Matija Obreza's avatar
Matija Obreza committed
1
import update from 'immutability-helper';
Maxym Borodenko's avatar
Maxym Borodenko committed
2 3 4 5

import { UPDATE_HISTORY } from 'constants/history';

const INITIAL_STATE: {
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
6
    hasHistory: boolean,
Maxym Borodenko's avatar
Maxym Borodenko committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    lastLocation: string;
} = {
    hasHistory: false,
    lastLocation: '/',
};

export default function history(state = INITIAL_STATE, action: { type?: string, payload?: any } = {type: '', payload: {}}) {

    switch (action.type) {
        case UPDATE_HISTORY: {
            return update(state, {
                hasHistory: {$set: true},
                lastLocation: {$set: action.payload},
            });
        }

        default:
            return state;
    }
}