1.3.7 ā€¢ Published 2 years ago

@webiz/redux-common v1.3.7

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Description

@webiz/redux-common generates Higher-Order reducers 
and simplifies async actions for your redux application

Install

npm install @webiz/redux-common

Usage Example

Action Creator

// ProductActions.ts

import { asyncActionCreator , IAsyncActions  } from '@webiz/redux-common';
import * as actionTypes from "./ProductTypes"

export const getProductAction: IAsyncActions = asyncActionCreator(actionTypes.GET_PRODUCT);
// ProductThunks.ts

import { getProductAction } from "./ProductActions";

export const getProduct = (id : number) => {
    return async dispatch => {
        try {

            dispatch(getProductAction.request())

            const product = await axios.get<IProduct>(`/product/${id}`)

            dispatch(getProductAction.success(product));

        } catch (ex) {
            dispatch(getProductAction.fail(ex));
        }
    };
};

High Order Reducer

// productReducer.ts

import { getProductAction } from "./ProductActions";
import { withAsyncStatus , initialAsyncState , initialAsyncState } from '@webiz/redux-common';

export const initialState: ProductState = {
        product: {
            ...initialAsyncState,
        },
    }

export default (state = initialState, action) => {
    switch (action.type) {
        case getProductAction.REQUEST :
        case getProductAction.SUCCESS :
        case getProductAction.FAIL :
            return {
                ...state,
                product: withAsyncStatus(state.product, action , getProductAction),
            };

        default:
            return state;
    }
};

Author

šŸ‘¤ Webiz

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.2.0

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago