Redux middleware

This commit is contained in:
Rodrigo Pedroso 2019-06-19 15:38:21 -04:00
commit 8c3335094a
2 changed files with 31 additions and 3 deletions

View file

@ -0,0 +1,22 @@
import { ADD_ARTICLE } from "../constants/action-types"
const forbiddenWords = ["spam", "money"]
export function forbiddenWordsMiddleware({ dispatch }) {
return function(next) {
return function(action) {
// do your stuff
if (action.type === ADD_ARTICLE) {
const foundWord = forbiddenWords.filter(word =>
action.payload.title.includes(word)
)
if (foundWord.length) {
return dispatch({ type: "FOUND_BAD_WORD" })
}
}
return next(action)
}
}
}