const subscribeMiddleware = () => store => { let handlers = []; store.subscribe = (cb) => { handlers = handlers.concat(cb); const removeSubscriber = () => { handlers = handlers.filter(fn => fn !== cb) }; return removeSubscriber; }; return next => (action) => { const previousState = store.getState(); next(action); const nextState = store.getState(); if (previousState !== nextState) handlers.forEach(cb => cb()); } };