Skip to content

Instantly share code, notes, and snippets.

@tkh44
Created November 4, 2016 18:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tkh44/be71388502a2c60133c9cd54f6e958ee to your computer and use it in GitHub Desktop.
Save tkh44/be71388502a2c60133c9cd54f6e958ee to your computer and use it in GitHub Desktop.
Example of syncing some redux state with a service worker
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