Created
March 7, 2018 19:41
-
-
Save lmorchard/8cd0456aa2cab07d9e9b587cc51be306 to your computer and use it in GitHub Desktop.
Redux middleware sending messages to add-on on state changes
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
const postMessage = (type, data = {}) => | |
window.postMessage( | |
{ ...data, type, channel: `${CHANNEL_NAME}-extension` }, | |
"*" | |
); | |
const updateExtensionThemeMiddleware = ({ getState }) => next => action => { | |
const returnValue = next(action); | |
const meta = action.meta || {}; | |
if (!meta.skipAddon && themeChangeActions.includes(action.type)) { | |
postMessage("setTheme", { theme: selectors.theme(getState()) }); | |
} | |
return returnValue; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment