Clean up middleware
This commit is contained in:
parent
5c7411594f
commit
466cde06b1
3 changed files with 10 additions and 22 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
import { createStore, applyMiddleware, compose } from 'redux'
|
||||
import rootReducer from '../reducers/index'
|
||||
import { forbiddenWordsMiddleware } from '../middleware'
|
||||
import createSagaMiddleware from "redux-saga"
|
||||
import apiSaga from "../sagas/api-saga"
|
||||
|
||||
|
@ -9,7 +8,7 @@ const storeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
|
|||
|
||||
const store = createStore(
|
||||
rootReducer,
|
||||
storeEnhancers(applyMiddleware(forbiddenWordsMiddleware, initialiseSagaMiddleware))
|
||||
storeEnhancers(applyMiddleware(initialiseSagaMiddleware))
|
||||
)
|
||||
|
||||
initialiseSagaMiddleware.run(apiSaga)
|
||||
|
|
9
src/tests/components/List.test.js
Normal file
9
src/tests/components/List.test.js
Normal 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)
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue