# redux-nc

> Redux no constants =========

Latest version **1.0.2** (published 2018-05-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install redux-nc
pnpm add redux-nc
yarn add redux-nc
bun add redux-nc
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-05-14 |
| First published | 2018-04-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 355.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | borm |
| Maintainers | _borm |
| Keywords | redux |

## Links

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

## Dependencies (2)

- [lodash.map](https://npm.io/package/lodash.map.md) ^4.6.0
- [lodash.mapvalues](https://npm.io/package/lodash.mapvalues.md) ^4.6.0

## Recent versions

- 1.0.2 (latest) — 2018-05-14
- 1.0.1 — 2018-04-23
- 1.0.0 — 2018-04-23

## README

Redux no constants
=========

A small library for working with redux without constants


## Installation

* npm: 
  `npm i -S redux-nc`

## Basic usage

1) First you need apply promise middleware

    ```
    import { promiseMiddleware } from 'redux-nc';

    applyMiddleware(..., promiseMiddleware);
    ``` 
    
2) Create the first action creator:

    ```
    import { createActions } from 'redux-nc';

    export default createActions('UNIQ_ACTIONS_NAME', {
      test: (...args) => true,
    });
    ```

3) Create reducer:

    ```
    import { createReducer, getActionIds } from 'redux-nc';
    import actions from 'actions';
    
    const types = getActionIds(actions);
    export default createReducer({
      // Define initial store
      test: false,
    }, {
      [types.test]: (state, action) => action.payload,
    });
    ```

4) Create the first async action creator:

    ```
    import { createActions, async } from 'redux-nc';

    export default createActions('UNIQ_ACTIONS_NAME', {
      @async()
      test(...args) {
        return (dispatch) => {
          dispatch(this.some(...ANY_DATA));
          return new Promise(resolve => resolve(true));
        }
      },
      
      some(...args) {
        return ...args;
      }
    });
    ```
    
4) Create reducer for async actions:

    ```
    import { createReducer, getActionIds } from 'redux-nc';
    import actions from 'actions';
    
    const types = getActionIds(actions);
    export default createReducer({
      // Define initial store
      test: false,
    }, {
      [types.test.begin]: (state, action) => action.payload,
      [types.test.success]: (state, action) => action.payload,
      [types.test.failed]: (state, action) => action.payload,
    });
    ```

5) Complete decorator:

    ```
    import { createActions, async, complete } from 'redux-nc';
    
    export default createActions('UNIQ_ACTIONS_NAME', {
      @async()
      /**
       * error: false/true - types.test.success / types.test.failed
       * payload: previus action result
       */
      @complete(({ error, payload }) => (dispatch) => {
        if (error) {
          
        } else {
          
        }
        // You can also use dispatch here
        // dispatch(this.some(...ANY_DATA));
        // NOTE: for use this, 
        // you should pass `function` not arrow func to @complete
      })
      test: () => new Promise(resolve => resolve(true)),
      
      some(...args) {
        return ...args;
      }
    });
    ```

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