0.1.22 • Published 7 years ago

redux-hook-middleware v0.1.22

Weekly downloads
137
License
MIT
Repository
github
Last release
7 years ago

redux-hook-middleware

Build Status Build status codecov runkit

npm (scoped) downloads Dependency Status devDependency Status

License: MIT

A Redux middleware to provide easy hooks on pre/post dispatch.

install

$ npm i redux-hook-middleware -S

usage

import { createStore, applyMiddleware } from 'redux'
import hookMiddleware, { registerPrehook } from 'redux-hook-middleware'

// redux setup
const initialState = { /* initial state */ }
const reducer = (state = initialState, action) => { /* reducer function logics */ return state }
const middlewares = [hookMiddleware]
const store = createStore(reducer, initialState, applyMiddleware(...middlewares))

// middleware logic
registerPrehook('HOOKING_ACTION_TYPE', (store, action) => {
  console.log('prehooked!')
  // do anything inside callback
  // you can also dispatch other actions
  store.dispatch({ type: 'SOME_ACTION_TYPE' })
})

// how does it works
store.dispatch({ type: 'HOOKING_ACTION_TYPE' }) // 'prehooked!'

APIs

registerPrehook(type<string>, hook<function>)<symbol>

Register a hook for former middleware chain and return uniq id for the hook.

registerPosthook(type<string>, hook<function>)<symbol>

Register a hook for later middleware chain and return uniq id for the hook.

registerPrehooks(hookObject<object>)<object>

Register hooks for former middleware chain and return uniq id for the hook. Pass an action type as key and a callback or an array of callbacks as value.

registerPosthooks(hookObject<object>)<onject>

Register hooks for later middleware chain and return uniq id for the hook. Pass an action type as key and a callback or an array of callbacks as value.

unregisterHook(id<symbol>)<void>

Unregister the hook with hook id.

clearHooks()<void>

Unregister all the hooks registered.

development

$ git clone https://github.com/kamataryo/redux-hook-middleware.git
$ cd redux-hook-middleware
$ npm test
0.1.22

7 years ago

0.1.21

7 years ago

0.1.20

7 years ago

0.1.19

7 years ago

0.1.18

7 years ago

0.1.17

7 years ago

0.1.16

7 years ago

0.1.15

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago