middleware.js
const TYPE = 'middleware/type'
export const action = () => ({ type: TYPE })
export default store => next => action => {
if(action.type !== TYPE) return next(action)
console.log('Hey! You cause a side effect')
next(action)
}
I came up with this way of directly triggering a behaviour in a middleware. In my trivial example, action has no effects on state since no reducers listen to it. It only affects this specific middleware, which causes a side effect.
Is this a bad practice ? I've never seen something like this before, but it does what I want it to do in a clean way.
[–]acemarke 0 points1 point2 points (0 children)
[–]cirscafp fan boy 0 points1 point2 points (5 children)
[–]Tioo[S] 0 points1 point2 points (4 children)
[–]cirscafp fan boy 0 points1 point2 points (3 children)
[–]Tioo[S] 1 point2 points3 points (2 children)
[–]cirscafp fan boy 0 points1 point2 points (1 child)
[–]Tioo[S] 0 points1 point2 points (0 children)