-
-
Save m7v/9b41c41f02e5016f25272e9a91f94172 to your computer and use it in GitHub Desktop.
Example of syncing some redux state with a service worker
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 swSupported = !!('serviceWorker' in navigator) | |
const sendMessage = (messageData) => { | |
if (!swSupported) { | |
return | |
} | |
navigator.serviceWorker.controller.postMessage(messageData) | |
} | |
sendMessage({ sideway: window.sideway }) | |
export const serviceWorkerMiddleware = (store) => (next) => (action) => { | |
const result = next(action) | |
if (action.type.indexOf('auth/') === 0) { | |
sendMessage({ auth: store.getState().auth }) | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment