redux-mitt

2.1.2 • Public • Published

redux-mitt

Latest Version CircleCI

what is this?

The redux standard API does not have an easy way to subscribe Actions and unsubscribe them.added this as a lightweight function.

install

$ npm install --save redux-mitt

setup

import { createStore, applyMiddleware } from 'redux'
import { mittMiddleware } from 'redux-mitt'

const reducer = () => {}
const store = createStore(reducer, mittMiddleware())

usage

const type = 'TEST'
const payload = { test: 'test' }
const creator = () => { return { type, payload }}
const unsubscribe = store.subscribeAction(type, action => {
  console.log(action) // { type: 'TEST', payload: { test: 'test'} }
})
// unsubscribe() # unsubscribe action
store.dispatch(creator())

API

subscribeAction(type, handler)

The first argument specifies the action type. Specific action ex:) 'SOME_ACTION' or wildcard '*' can subscribe.The second argument is callback with action.

Readme

Keywords

none

Package Sidebar

Install

npm i redux-mitt

Weekly Downloads

1

Version

2.1.2

License

MIT

Unpacked Size

7.36 kB

Total Files

8

Last publish

Collaborators

  • takepepe