dispatch-hijack

1.2.0 • Public • Published

Dispatch Hijack

Dispatch Hijack middleware allows you to write redux side effects on a per-action basis.

Build Status npm version semantic-release

Motivation

Redux action side effects can be managed based on action.type with a switch statement within a custom middleware. However, this case logic can be a pain to manage and tend to be too abstracted from the original action that triggers it.

Dispatch Hijack allows side effects to be written on a per-action basis -- without complicated case logic.

Installation

npm install --save dispatch-hijack

Then, to enable Dispatch Hijack, use applyMiddleware():

import { createStore, applyMiddleware } from "redux";
import hijack from "dispatch-hijack";
import rootReducer from "./reducers/index";

// Note: this API requires redux@>=3.1.0
const store = createStore(rootReducer, applyMiddleware(hijack));

Basic Usage

Add the hijack key to any action. The hijack key will be removed before passing the action to the next middleware or reducer.

const normalAction = {
  type: "ACTION"
};

const hijackedAction = {
  type: "ACTION",
  hijack: action => {
    console.log("Hijacked");
    return action;
  }
};

Package Sidebar

Install

npm i dispatch-hijack

Weekly Downloads

6

Version

1.2.0

License

MIT

Unpacked Size

5.92 kB

Total Files

3

Last publish

Collaborators

  • zachary.sierakowski