@mollycule/redux-operation
v1.1.6
Published
A utility to simplify creation of redux operations like loading, success, failure automatically
Downloads
3
Maintainers
Readme
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
- Wrap the root app component with
redux-hook
provider by callingcreateStoreContext<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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Param Singh - @paramsinghvc - [email protected]
Project Link: https://github.com/paramsinghvc/redux-operation