Basics

This example will show you a simple reducer without any override and what this will generate.

Code

import { Rule, Generator } from 'redux-autoreducers';
const rule = new Rule('GET_ALL');
const generator = new Generator([rule]);
const reducer = generator.generate();
export default reducer;

Result

The example before will generate :

const initialState = {
    isGetAllPending: true,
    getAllData: null,
    getAllError: null,
};

function reducer(state = initialState, action) {
    switch (action.type) {
        case 'GET_ALL_PENDING':
            return {
                ...state,
                isGetAllPending: true,
                getAllData: null,
                getAllError: null,
            };
        case 'GET_ALL_REJECTED':
            return {
                ...state,
                isGetAllPending: false,
                getAllError: action.error,
            };
        case 'GET_ALL_FULFILLED':
            return {
                ...state,
                isGetAllPending: false,
                getAllData: action.data,
            };
        default:
            return state;
    }
}

export default reducer;

results matching ""

    No results matching ""