rename service worker actions to do/did pattern

This commit is contained in:
David Lechner
2021-01-15 11:23:26 -06:00
parent f54beab97f
commit efb474b727
3 changed files with 13 additions and 13 deletions
+8 -8
View File
@@ -4,8 +4,8 @@
import { Action } from 'redux';
export enum ServiceWorkerActionType {
Update = 'serviceWorker.update',
Success = 'serviceWorker.success',
DidUpdate = 'serviceWorker.didUpdate',
DidSucceed = 'serviceWorker.didSucceed',
}
export type ServiceWorkerAction<
@@ -14,14 +14,14 @@ export type ServiceWorkerAction<
registration: ServiceWorkerRegistration;
};
export function update(
export function didUpdate(
registration: ServiceWorkerRegistration,
): ServiceWorkerAction<ServiceWorkerActionType.Update> {
return { type: ServiceWorkerActionType.Update, registration };
): ServiceWorkerAction<ServiceWorkerActionType.DidUpdate> {
return { type: ServiceWorkerActionType.DidUpdate, registration };
}
export function success(
export function didSucceed(
registration: ServiceWorkerRegistration,
): ServiceWorkerAction<ServiceWorkerActionType.Success> {
return { type: ServiceWorkerActionType.Success, registration };
): ServiceWorkerAction<ServiceWorkerActionType.DidSucceed> {
return { type: ServiceWorkerActionType.DidSucceed, registration };
}
+3 -3
View File
@@ -10,7 +10,7 @@ import { applyMiddleware, createStore } from 'redux';
import { createLogger } from 'redux-logger';
import createSagaMiddleware from 'redux-saga';
import './index.scss';
import { success, update } from './actions/service-worker';
import { didSucceed, didUpdate } from './actions/service-worker';
import App from './components/App';
import NotificationStack from './components/NotificationStack';
import rootReducer from './reducers';
@@ -76,8 +76,8 @@ ReactDOM.render(
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://cra.link/PWA
serviceWorkerRegistration.register({
onUpdate: (r) => store.dispatch(update(r)),
onSuccess: (r) => store.dispatch(success(r)),
onUpdate: (r) => store.dispatch(didUpdate(r)),
onSuccess: (r) => store.dispatch(didSucceed(r)),
});
// If you want to start measuring performance in your app, pass a function
+2 -2
View File
@@ -147,7 +147,7 @@ const list: Reducer<NotificationList, Action> = (state = [], action) => {
];
case NotificationActionType.Remove:
return state.filter((e) => e.id !== action.id);
case ServiceWorkerActionType.Update:
case ServiceWorkerActionType.DidUpdate:
return append(
state,
Level.Info,
@@ -155,7 +155,7 @@ const list: Reducer<NotificationList, Action> = (state = [], action) => {
undefined,
'https://github.com/pybricks/pybricks-code/issues/102',
);
case ServiceWorkerActionType.Success:
case ServiceWorkerActionType.DidSucceed:
return append(state, Level.Info, MessageId.ServiceWorkerSuccess);
default:
return state;