Home Reference Source

application/redux/reducers/site-reducers.js

import _ from 'lodash';
import Immutable from 'immutable';
import {
    SITE_REQUEST,
    SITE_RECEIVE,
    SITE_INVALIDATE,
    SITE_RECEIVE_ROUTES,
    SITE_RECEIVE_SSL
} from './../actions/site-actions';

export function site(state = null, action) {
    if (state === null) {
        state = {
            isFetching: false,
            didInvalidate: false,
            information: Immutable.fromJS({}),
            routes: Immutable.fromJS([]),
            ssl: Immutable.fromJS({})
        };
    }

    let newState;

    switch (action.type) {
        case SITE_INVALIDATE:
            return Object.assign({}, state, {
                didInvalidate: true,
            });
        case SITE_REQUEST:
            return Object.assign({}, state, {
                isFetching: true,
                didInvalidate: false
            });
        case SITE_RECEIVE:
            return Object.assign({}, state, {
                isFetching: false,
                didInvalidate: false,
                information: action.payload.information
            });
        case SITE_RECEIVE_ROUTES:
            return Object.assign({}, state, {
                isFetching: false,
                didInvalidate: false,
                routes: action.payload.routes
            });
        case SITE_RECEIVE_SSL:
            return Object.assign({}, state, {
                isFetching: false,
                didInvalidate: false,
                ssl: action.payload.ssl
            });
    }

    return state;
};