# drmzn-redux

> Action-reducers for Redux

Latest version **0.2.2** (published 2019-02-23) · MIT License license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2019-02-23 |
| First published | 2019-02-22 |
| Weekly downloads | 0 |
| License | MIT License |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | alex.tzvetanov@gmail.com |
| Maintainers | alex.tzvetanov |
| Keywords | redux, action-reducer |

## Links

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

## Recent versions

- 0.2.2 (latest) — 2019-02-23
- 0.2.1 — 2019-02-23
- 0.2.0 — 2019-02-22
- 0.1.0 — 2019-02-22

## README

# drmzn-redux

#### Actions, Reducers and action-reducers

Redux provides us with actions and reducers. Actions and reducers are meant to be separated, so reducers can be reused and be composable.

However, sometimes is more suitable to combine them at one place.

In order to use **action-reducer**, you create a namespace (shortcut for IIFE in typescript).

Every action-reducer function must have ```type```, ```dispatch``` and ```reduce``` methods.

##### Action-reducer

```typescript
export namespace mySimpleAction {
    export const type = 'TEST_TYPE';
    export const dispatch(store, payload) {
        store.dispatch({
            type,
            payload
        }); 
    }
    export const reduce(state, action) => immutable(state)
        .set('Some.section.subsection.test', action.payload)
        .set('Some.another.subsection.test', true)
        .value();
}
```

Here we are using **[object-path-immutable](https://github.com/mariocasciaro/object-path-immutable)** to update the state.

##### How to dispatch an action

```typescript
actions.mySimpleAction.dispatch(store, payload)
```

To dispatch and action, you need to pass the **initialized store object** as first variable and your data object as payload.

##### How to use with createStore?

Import your action-reducers and pass them to ```actionReducer```.

```typescript
import { createStore } from 'redux';
import { actionReducer } from 'drmzn-redux';
import * as actions from './src/actions';

createStore(actionReducer(actions), ...);
```

**What else you can find in this package?**

#### hydrate

hydrate function that loads state from ```window.__PRELOADED_STATE__```.

#### extension

extension function that loads Redux extension.

**How to use:**

```typescript
import { createStore } from 'redux';
import { actionReducer, hydrate, extension } from 'drmzn-redux';
import * as actions from './src/actions';

createStore(actionReducer(actions), hydrate, extension);
```

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