Skip to content

Instantly share code, notes, and snippets.

@jwarby
Created October 6, 2016 00:26
Show Gist options
  • Save jwarby/eae50cd50a88c67298231c4197efe4a1 to your computer and use it in GitHub Desktop.
Save jwarby/eae50cd50a88c67298231c4197efe4a1 to your computer and use it in GitHub Desktop.
A saga for redux-saga 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.
import { takeEvery } from 'redux-saga'
import { isFSA } from 'flux-standard-action'
const alreadyWarnedAbout = []
export function* fsaCompliance() {
yield* takeEvery('*', function* checkCompliance(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)
}
})
}
@jwarby
Copy link
Author

jwarby commented Oct 6, 2016

Usage

import { applyMiddleware, createStore } from 'redux'
import createSagaMiddleware from 'redux-saga'

import fsaCompliance from 'path/to/fsaCompliance.js'

const sagaMiddleware = createSagaMiddleware()

/* ...snip... */
let store = createStore(
  rootReducer,
  applyMiddleware(
    /* ...snip other middleware... */
   sagaMiddleware
  )
)

sagaMiddleware.run(fsaCompliance)

/* ...snip... */

Additional dependencies

Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment