# actiontypemiddleware

> Middleware for watching actions that pass through the store and subscribing to them

Latest version **1.0.1** (published 2017-12-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install actiontypemiddleware
pnpm add actiontypemiddleware
yarn add actiontypemiddleware
bun add actiontypemiddleware
```

## 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.1 |
| Published | 2017-12-01 |
| First published | 2017-12-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kesupile |
| Maintainers | kesupile |
| Keywords | redux, action, middleware, subscribe actions, typechecking, type |

## Links

- npm: https://www.npmjs.com/package/actiontypemiddleware
- Repository: https://github.com/kesupile/actiontypemiddleware
- Homepage: https://github.com/kesupile/actiontypemiddleware#readme
- Issues: https://github.com/kesupile/actiontypemiddleware/issues
- npm.io page: https://npm.io/package/actiontypemiddleware

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-12-01
- 1.0.0 — 2017-12-01

## README

# actiontypemiddleware
This middleware allows you to subscribe to a redux-store on a case-by-case basis depending on what type of action has been called. It's super easy to use and is useful for various scenarios including unit testing

## Installation
```
npm install ---save-dev actiontypemiddleware
```

## Properties
### *middleware*
(function) the main middleware function

### *subscriptions*
(object) the list of subscriptions to the middleware




## Methods
### *subscribe(name, type, callback)*
**name**: (string) the name of the subscription. Multiple action types can be subscribed under the same name.

**type**: (string) the redux action type.

**callback**: (function) the callback function invoked whenever the subscribed action is dispatched to the store.
The callback accepts an object of the following structure: {**timestamp**: *date in milliseconds*, **action**: *dispatched action*}

### *unsubscribe(name)*
**name**: (string) the name of the subscription to remove.

### *unsubscribeAction(name, type)*
**name**: (string) the name of the subscription.

**type**: (string) the specific action type to unsubscribe from under this name. If there is only one action subscribed under this name then it will remove the entire subscription


## Usage
The following usage assumes you are familiar with redux actions and redux stores. For further information please refer to [this excellent documentation](https://redux.js.org/docs/introduction/).

The middleware works on a subscription based model, meaning you can turn it on and off at will.

```javascript
import ACTIONTYPEM from 'actiontypemiddleware'
import { createStore, applyMiddleware } from 'redux'
import reducers from './reducers'

/* import this object wherever it's needed and turn it on and off to listen for actions */
export const signOutButton = {
    on() {
        ACTIONTYPEM.subscribe('signout', 'USER_SIGN_OUT', signOutButton.listener)
    },
    off() {
        ACTIONTYPEM.unsubscribe('signout')
    },
    listner({timestamp, action}){
        console.log(`someone signed out at: ${timestamp}`)
        console.log('the action data is', action)
    }
}

export default createStore(reducers, applyMiddleware(ACTIONTYPEM.middleware))
```

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