Last active
July 17, 2020 08:55
-
-
Save sanusart/3498edbab01b2f2cc820233e268089f4 to your computer and use it in GitHub Desktop.
Redux meta-middlware to add some meta to every action #redux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { PACKAGE_NAME } from 'src/constants'; | |
const metaMiddleware = ({ getState }) => next => (action) => { | |
const store = getState(); | |
const user = store[PACKAGE_NAME].user; | |
const transport = store[PACKAGE_NAME].transport; | |
next({ | |
...action, | |
meta: { | |
user: { | |
isSeller: user.isSeller, | |
isSysAdmin: user.isSysAdmin, | |
isBuyer: !user.isSeller && !user.isSysAdmin, | |
}, | |
activeTab: transport.activeTab, | |
...action.meta, | |
}, | |
}); | |
}; | |
export default metaMiddleware; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment