redux-dispatch-subscribe

1.0.0 • Public • Published

redux-dispatch-subscribe

npm version

Store enhancer for redux which allows listening of dispatched actions.

npm install --save redux-dispatch-subscribe

Usage

The dispatchSubscribe store enhancer add a addDispatchListener to your Redux store. The dispatch listener of called after regular store listeners. Since dispatchSubscribe overloads the dispatch on the original redux store it is important that it gets applied before any other store enhancers or middleware that depend on these functions; The compose utility in redux can be used to handle this:

import { createStore, applyMiddleware, compose } from 'redux';
import { dispatchSubscribe } from 'redux-dispatch-subscribe';
 
const enhancer = compose(
  applyMiddleware(...middleware),
  dispatchSubscribe((notify) => {
    notify();
  })
)
 
// Note: passing enhancer as the last argument to createStore requires redux@>=3.1.0
const store = createStore(reducer, initialState, enhancer);

Note: since compose applies functions from right to left, dispatchSubscribe should appear at the end of the chain.

Thanks

Implementation is inspired from redux-batched-subscribe.

Dependencies (0)

    Dev Dependencies (7)

    Package Sidebar

    Install

    npm i redux-dispatch-subscribe

    Weekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • slorber