redux-validate-fsa
Version:
Redux middleware that validates if an action is a Flux Standard Action (FSA)
43 lines (29 loc) • 1.64 kB
Markdown
//nodei.co/npm/redux-validate-fsa.png?compact=true)](https://www.npmjs.com/package/redux-validate-fsa)
[](https://travis-ci.org/buunguyen/redux-validate-fsa)
Redux middleware that validates if an action is a [Flux Standard Action](https://github.com/acdlite/flux-standard-action) (FSA).
```js
const middleware = [reduxThunk]
// Only use in DEV mode
if (__DEV__) {
const fsaMiddleware = require('redux-validate-fsa')(ignore /* optional */)
middleware.push(fsaMiddleware)
}
```
The `ignore` argument specify actions that should be skipped from the FSA check. This is useful when dealing with non-compliant actions from third-party libraries.
* If an array is given, it is the action types that should be skipped from the FSA check.
* If a function is given, it must return true for actions that should be skipped from the FSA check.
For example, if you use [redux-simple-router](https://github.com/jlongster/redux-simple-router), you should ignore its update-path actions, which are not FSA compliant.
```js
import {UPDATE_PATH} from 'redux-simple-router'
const fsaMiddleware = require('redux-validate-fsa')([UPDATE_PATH])
```
Notes:
* This middleware is only useful in dev mode. Therefore, it should be conditionally imported.
* If you use [redux-thunk](https://github.com/gaearon/redux-thunk), make sure the thunk middleware is added before this middleware. Alternatively, you can use the `ignore` predicate to filter out actions that are thunks.
```bash
npm install
npm test
```
[![NPM](https: