0.1.0 • Published 9 years ago
redux-sw-middleware v0.1.0
Redux Service Worker Middleware
This middleware registers a service worker for your application and enables Redux to receive actions based on events of the service worker.
Install
npm install --save redux-sw-middlewareExample
First add the middleware to redux. You need to pass the path to the service worker file as a parameter.
import createServiceWorkerMiddleware from 'redux-service-worker-middleware'
const serviceWorkerMiddleware = createServiceWorkerMiddleware('/service-worker.js')
const store = createStore(
reducer,
initialState,
applyMiddleware(serviceWorkerMiddleware)
)The middleware will register the service worker and dispatch actions based on state changes of the service worker.
Actions
SERVICE_WORKER_AVAILABLE: The service worker has downloaded all files is up and running
{
type: 'SERVICE_WORKER_AVAILABLE'
}SERVICE_WORKER_NEW_CONTENT: New content is available and will be loaded on the next page reload
{
type: 'SERVICE_WORKER_NEW_CONTENT'
}SERVICE_WORKER_REDUNDANT: The service worker became redundant
{
type: 'SERVICE_WORKER_REDUNDANT'
}SERVICE_WORKER_ERROR: An error occured
{
type: 'SERVICE_WORKER_ERROR',
payload: <exception>
}License
MIT
0.1.0
9 years ago