# redux-packish

> Sensibleless promise handling and middleware for redux

Latest version **1.0.0** (published 2020-02-13) · MIT license · 0 weekly downloads

## Install

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

## 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.0 |
| Published | 2020-02-13 |
| First published | 2020-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 18.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Matheus Rodrigues |
| Maintainers | matheusrod92 |
| Keywords | redux, middleware, promise, async, normalize, normalizr, react |

## Links

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

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^3.0.1
- [deline](https://npm.io/package/deline.md) ^1.0.4
- [invariant](https://npm.io/package/invariant.md) ^2.2.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-02-13

## README

# Redux Packish

Sensible**less** promise handling and middleware for redux

`redux-pack` is a library that introduces promise-based middleware that allows async actions based on the lifecycle of a promise to be declarative.

And `redux-packish` is a library that cloned `redux-pack` allowing anyone dispatch actions from side-effects!

:warning: **NOW STOP USING THUNKS WITH PACK TO DISPATCH YOUR SIDE-EFFECTS!**

~~Async actions in redux are often done using `redux-thunk` or other middlewares. The problem with this approach is that it makes it too easy to use `dispatch` sequentially, and dispatch multiple "actions" as the result of the same interaction/event, where they probably should have just been a single action dispatch.~~

~~This can be problematic because we are treating several dispatches as all part of a single transaction, but in reality, each dispatch causes a separate rerender of the entire component tree, where we not only pay a huge performance penalty, but also risk the redux store being in an inconsistent state.~~

~~`redux-pack` helps prevent us from making these mistakes, as it doesn't give us the power of a `dispatch` function, but allows us to do all of the things we were doing before.~~

To give you some more context into the changes, here are some examples/information about the old way and new way of doing things below:

Ready to use it? Jump straight to the [How-To and API OFFICIAL DOC](https://github.com/lelandrichardson/redux-pack/#how-to)

### Adding side-effects with event hooks

You might want to add side effects (like sending analytics events or navigate to different views) based on promise results.

`redux-pack` lets you do that through event hooks functions. These are functions attached to the `meta` attribute of the original action. They are called with ~~two~~ THREE!! parameters:

1. the matching step payload (varies based on the step, details below)
2. **the `dispatch` function**
3. the `getState` function

Here are the available hooks and their associated payload:

* `onStart`, called with the initial action `payload` value
* `onFinish`, called with `true` if the promise resolved, `false` otherwise
* `onSuccess`, called with the promise resolution value
* `onFailure`, called with the promise error

Here is an example usage to send analytics event when the user `doesFoo`:

```js
import { sendAnalytics } from '../analytics';
import { doFoo } from '../api/foo';

export function userDoesFoo() {
  return {
    type: DO_FOO,
    promise: doFoo(),
    meta: {
      onSuccess: (result, dispatch, getState) => {
        const userId = getState().currentUser.id;
        const fooId = result.id;
        sendAnalytics('USER_DID_FOO', {
          userId,
          fooId,
        });

        dispatch({
          type: 'HOLY_MOTHER_OF_GOD_WE_CAN_DISPATCH_HERE_NOW',
        });
      }
    }
  }
}
```

### Notes

This project is based on [redux-pack](https://github.com/lelandrichardson/redux-pack) with some **A W E S O M E** changes! You can check the official docs at their repository!

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