redux-store-utility

    2.0.4 • Public • Published

    Redux store utility

    A utility to simplify creation of Redux store by creating

    • Action constants
    • Actions,
    • Async actions
    • Reducer

    Installation

    npm install redux-store-utility
    

    Documentation

    Create Redux store for "PRODUCTS" as follows

    store.js

    import { createStore, applyMiddleware } from "redux";
    import thunk from "redux-thunk";
    import beginInitialState from "./initialState.json";
    import rootReducer from "./rootReducer";
     
     
    const store = createStore(
        rootReducer,
        beginInitialState,
        applyMiddleware( thunk )
    );
     
    export default store;

    rootReducer.js

    import { combineReducers } from "redux";
    import reduxStoreUtility from "redux-store-utility";
     
    const pr = reduxStoreUtility.createReducer( "PRODUCTS" )
     
    const app = combineReducers( {
        products: pr.productsReducer,
    } );
     
    export default app;

    initialState.json

    {
      "products": {
        "pending": false,
        "error": false,
        "list": []
      }
    }

    To get synchronous actions

    import reduxStoreUtility from "redux-store-utility";
     
    const syncActions = reduxStoreUtility.createActions( "Products" );

    It will create following actions

    • product Reset
    • product Pending
    • product Success
    • product Error

    For fetching (async action) from api and putting in "PRODUCTS" store use as follows

    import reduxStoreUtility from "redux-store-utility";
     
    const asyncActions = reduxStoreUtility.createAsyncActions( "Products" );
     
    const request = new Request( 'http://localhost:3002/',
                                    {
                                       method: 'GET',
                                       headers: { 'Accept': 'application/json' }
                                    } );
     
    const productsFetch = dispatch => request => dispatch( asyncActions.productsFetch( request ) );

    Install

    npm i redux-store-utility

    DownloadsWeekly Downloads

    6

    Version

    2.0.4

    License

    GNU

    Unpacked Size

    44 kB

    Total Files

    9

    Last publish

    Collaborators

    • petercraftsmn