Skip to content

Instantly share code, notes, and snippets.

@lmorchard
Created March 7, 2018 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmorchard/8cd0456aa2cab07d9e9b587cc51be306 to your computer and use it in GitHub Desktop.
Save lmorchard/8cd0456aa2cab07d9e9b587cc51be306 to your computer and use it in GitHub Desktop.
Redux middleware sending messages to add-on on state changes
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