Last active
October 6, 2016 00:27
-
-
Save jwarby/7ab709c80701ce349e1e191bc795deda to your computer and use it in GitHub Desktop.
A middleware for Redux which verifies that all actions dispatched to the store follow the Flux Standard Action (https://github.com/acdlite/flux-standard-action) pattern. A warning is shown (only once) for each action which violates the pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { isFSA } from 'flux-standard-action' | |
function createFSAComplianceMiddleware() { | |
const alreadyWarnedAbout = [] | |
return ({ dispatch, getState }) => next => action => { | |
const { type } = action | |
if (!isFSA(action) && alreadyWarnedAbout.indexOf(type) === -1) { | |
// eslint-disable-next-line no-console | |
console.warn(`${type} does not conform to the Flux Standard Action pattern`) | |
alreadyWarnedAbout.push(type) | |
} | |
return next(action) | |
} | |
} | |
const fsaCompliance = createFSAComplianceMiddleware() | |
export default fsaCompliance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Additional dependencies
flux-standard-action
Notes