# create-redux-routines

> To create actions and reducers in one go

Latest version **1.1.0** (published 2018-06-03) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install create-redux-routines
pnpm add create-redux-routines
yarn add create-redux-routines
bun add create-redux-routines
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-06-03 |
| First published | 2018-05-30 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 23.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Kritivasas Shukla |
| Maintainers | kritivasas |
| Keywords | redux, actions, reducers, createActions, createReducers |

## Links

- npm: https://www.npmjs.com/package/create-redux-routines
- Repository: https://github.com/VariableVasasMT/create-redux-routines
- Homepage: https://github.com/VariableVasasMT/create-redux-routines#readme
- Issues: https://github.com/VariableVasasMT/create-redux-routines/issues
- npm.io page: https://npm.io/package/create-redux-routines

## Dependencies (3)

- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0
- [is-plain-object](https://npm.io/package/is-plain-object.md) ^2.0.4
- [babel-preset-env](https://npm.io/package/babel-preset-env.md) ^1.7.0

## Recent versions

- 1.1.0 (latest) — 2018-06-03
- 1.0.8 — 2018-06-02
- 1.0.7 — 2018-06-02
- 1.0.6 — 2018-06-02
- 1.0.5 — 2018-06-01
- 1.0.4 — 2018-05-31
- 1.0.3 — 2018-05-31
- 1.0.2 — 2018-05-31
- 1.0.1 — 2018-05-30
- 1.0.0 — 2018-05-30

## README

# create-redux-routines

```
import { getLoadingActions } from 'create-redux-routines/createActions'
const { LOADING, SUCCESS, FAIL, RESET, FULLFILL } = getLoadingActions( "FETCH_INIT_DATA" );

FAIL: "FETCH_INIT_DATA_FAIL",
LOADING: "FETCH_INIT_DATA",
SUCCESS: "FETCH_INIT_DATA_SUCCESS",
TRIGGER: "FETCH_INIT_DATA_TRIGGER"
FULLFILL: "FETCH_INIT_DATA_FULLFILL",
```


```
import ReduxObject from 'create-redux-routines'
var reduxObject = new ReduxObject([
  {
    name: 'FETCH_INIT_DATA',
    options: { async: true }
  },
  {
    name: 'UPDATE_MODULE_STATE',
    options: {
      key: "moduleState"
    }
  },
  {
    name: 'UPDATE_SECTIONS',
    options: {
      key: "sections"
    }
  },
  {
    name: 'UPDATE_LEVELS',
    options: {
      key: "levels"
    }
  },
  {
    name: 'UPDATE_TASKS',
    options: {
      key: "tasks"
    }
  },
  {
    name: 'MANIPULATE_DATA',
    options: {
      key: "operationStatus",
      async: true
    }
  },
  {
    name: 'MIXPANEL',
    options: {
      key: "mixpanel"
    }
  }
]);
```
gets you 
![alt text](https://i.imgur.com/EcMHW5n.png)


Options:

```
var reduxObject = new ReduxObject([{
  name: 'FETCH_INIT_DATA',
  options: { 
    async: true,
    merge: false 
  }
},{
  name: 'GET_INFO',
  options: { 
    async: true,
    merge: false,
    key: 
  }
}])
```
this is will return

```
ReduxObject: {
  actions: {
    FETCH_INIT_DATA: {
      FAIL: "FETCH_INIT_DATA_FAIL",
      LOADING: "FETCH_INIT_DATA",
      SUCCESS: "FETCH_INIT_DATA_SUCCESS",
      TRIGGER: "FETCH_INIT_DATA_TRIGGER",
      FULLFILL: "FETCH_INIT_DATA_FULLFILL",
      fail: (error = {}, meta = {}) => {
        return {
          type: FAIL,
          payload: error.error ? error : { error },
          meta
        };
      },
      success: (data = {}, meta) => {
        return {
          type: SUCCESS,
          payload: {
            ...data
          }, meta
        };
      },
      trigger: ( data = {}, meta ) => {
        return {
          type: TRIGGER,
          meta
        }
      },
      fullfill: ( data = {}, meta ) => {
        return {
          type: FULLFILL,
          meta
        }
      },
      loading: (payload, meta) => {
        return {
          type: actionType,
          payload: payload,
          meta: meta
        }
      }
    },
    GET_INFO: {
      FAIL: "GET_INFO_FAIL",
      LOADING: "GET_INFO_DATA",
      SUCCESS: "GET_INFO_SUCCESS",
      TRIGGER: "GET_INFO_TRIGGER",
      FULLFILL: "GET_INFO_FULLFILL",
      fail: (error = {}, meta = {}) => {
        return {
          type: FAIL,
          payload: error.error ? error : { error },
          meta
        };
      },
      success: (data = {}, meta) => {
        return {
          type: SUCCESS,
          payload: {
            ...data
          }, meta
        };
      },
      trigger: ( data = {}, meta ) => {
        return {
          type: TRIGGER,
          meta
        }
      },
      fullfill: ( data = {}, meta ) => {
        return {
          type: FULLFILL,
          meta
        }
      },
      loading: (payload, meta) => {
        return {
          type: actionType,
          payload: payload,
          meta: meta
        }
      }
    }
  },
  reducers: (state = initialState, action) => {
      let { data, error, ...rest } = action.payload || {};
      let { payload: userData = {}, loadingData } = action.meta || {};
      switch (action.type) {
        case LOADING:
          return {
            ...state,
            isLoading: true,
            loaded: false,
            hasError: false,
            loadingData: loadingData,
            error: undefined
          };
        case SUCCESS:
          return {
            ...state,
            isLoading: false,
            loaded: true,
            loadingData: undefined,
            data: data,
            hasError: false,
            error: undefined,
            ...rest
          };
        case FAIL:
          return {
            ...state,
            isLoading: false,
            loaded: true,
            data: undefined,
            loadingData: undefined,
            hasError: true,
            error: {
              ...this.customError(error),
              payload: userData
            },
            ...rest
          };
        case FULLFILL:
          return {
            ...state,
            isLoading: false,
            loaded: true
          }
        case RESET:
          return {
            isLoading: false,
            loaded: false,
            data: undefined,
            hasError: false,
            error: undefined,
            loadingData: undefined
          };
        default:
          return state;
      }
    };
}
```

---
_Source: https://npm.io/package/create-redux-routines · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
