Clean up middleware

This commit is contained in:
Rodrigo Pedroso 2019-06-22 22:19:13 -04:00
commit 466cde06b1
3 changed files with 10 additions and 22 deletions

View file

@ -1,20 +0,0 @@
import { ADD_ARTICLE } from "../constants/action-types"
const forbiddenWords = ["spam", "money"]
export function forbiddenWordsMiddleware({ dispatch }) {
return function(next) {
return function(action) {
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)
}
}
}

View file

@ -1,6 +1,5 @@
import { createStore, applyMiddleware, compose } from 'redux' import { createStore, applyMiddleware, compose } from 'redux'
import rootReducer from '../reducers/index' import rootReducer from '../reducers/index'
import { forbiddenWordsMiddleware } from '../middleware'
import createSagaMiddleware from "redux-saga" import createSagaMiddleware from "redux-saga"
import apiSaga from "../sagas/api-saga" import apiSaga from "../sagas/api-saga"
@ -9,7 +8,7 @@ const storeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const store = createStore( const store = createStore(
rootReducer, rootReducer,
storeEnhancers(applyMiddleware(forbiddenWordsMiddleware, initialiseSagaMiddleware)) storeEnhancers(applyMiddleware(initialiseSagaMiddleware))
) )
initialiseSagaMiddleware.run(apiSaga) initialiseSagaMiddleware.run(apiSaga)

View file

@ -0,0 +1,9 @@
import React from 'react'
import ReactDOM from 'react-dom'
import List from '../../components/List'
it('renders without crashing', () => {
const div = document.createElement('div')
ReactDOM.render(<App />, div)
ReactDOM.unmountComponentAtNode(div)
})