@mollycule/redux-operation
TypeScript icon, indicating that this package has built-in type declarations

1.1.6 • Public • Published

Build Status MIT License Contributors LinkedIn


Logo

Create Redux Operation

A utility to simplify creation of redux operations like loading, success, failure automatically
Explore the docs »

View Demo · Report Bug · Request Feature . NPM Link

Table of Contents

About The Project

A utility to simplify creation of redux operations like loading, success, failure automatically.

Built With

Getting Started

Prerequisites

  • Redux

Installation

npm i @mollycule/redux-operation -S

Usage

  1. Wrap the root app component with redux-hook provider by calling createStoreContext<IRootState> while specifying the shape of Redux App RootState into Generic Parameter.
import createReduxOperation, {
  actionFlags,
  augmentReducer,
  IReduxOperations,
  IAction
} from "@mollycule/redux-operation";

const {
  actions: [authRequest, authSuccess, authFailure],
  constants: authConstants,
  reducer: authenticationReducer
} = createReduxOperation("AUTHENTICATE");

export { authSuccess, authRequest, authFailure };

export interface ILoginState {
  metaProp: string;
}

const initialState = {
  metaProp: ""
};

const loginReducer = (
  state = initialState,
  action: IAction<symbol | string, any>
) => {
  switch (action.type) {
    case authConstants.get(actionFlags.REQUEST):
      return {
        ...state,
        metaProp: "SET NOW"
      };
    default:
      return state;
  }
};

export interface ILoginStateAugmented extends ILoginState {
  auth: IReduxOperations;
}

export default augmentReducer(loginReducer)({
  auth: authenticationReducer
});

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature)
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Param Singh - @paramsinghvc - paramsinghvc@gmail.com

Project Link: https://github.com/paramsinghvc/redux-operation

Acknowledgements

Dependents (0)

Package Sidebar

Install

npm i @mollycule/redux-operation

Weekly Downloads

3

Version

1.1.6

License

MIT

Unpacked Size

163 kB

Total Files

10

Last publish

Collaborators

  • paramsinghvc