Created
November 4, 2016 18:55
-
-
Save tkh44/be71388502a2c60133c9cd54f6e958ee to your computer and use it in GitHub Desktop.
Example of syncing some redux state with a service worker
This file contains hidden or 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