public.ts 567 Bytes
Newer Older
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
1 2 3
import update from 'immutability-helper';

import { IReducerAction } from 'model/common.model';
4
import { RECEIVE_CROPS } from 'crop/constants';
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
5 6

const INITIAL_STATE = {
7
    list: null,
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
8 9 10 11 12 13 14 15
    lastFetched: 0,
};

export default function crop(state = INITIAL_STATE, action: IReducerAction = {type: ''}) {

    switch (action.type) {
        case RECEIVE_CROPS: {
            return update(state, {
16
                list: {$set: action.payload},
Viacheslav Pavlov's avatar
Viacheslav Pavlov committed
17 18 19 20 21 22 23 24 25
                lastFetched: {$set: Date.now()},
            });
        }

        default:
            return state;
    }

}