diff --git a/src/app/reducers.test.ts b/src/app/reducers.test.ts index eb80f8df..10577b02 100644 --- a/src/app/reducers.test.ts +++ b/src/app/reducers.test.ts @@ -1,8 +1,11 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2021 The Pybricks Authors +// Copyright (c) 2021-2022 The Pybricks Authors import { AnyAction } from 'redux'; -import { didSucceed, didUpdate } from '../service-worker/actions'; +import { + serviceWorkerDidSucceed, + serviceWorkerDidUpdate, +} from '../service-worker/actions'; import { BeforeInstallPromptEvent } from '../utils/dom'; import { checkForUpdate, @@ -32,8 +35,10 @@ test('initial state', () => { test('serviceWorker', () => { const registration = {} as ServiceWorkerRegistration; expect( - reducers({ serviceWorker: null } as State, didSucceed(registration)) - .serviceWorker, + reducers( + { serviceWorker: null } as State, + serviceWorkerDidSucceed(registration), + ).serviceWorker, ).toBe(registration); }); @@ -59,7 +64,7 @@ test('checkingForUpdate', () => { expect( reducers( { checkingForUpdate: true } as State, - didUpdate({} as ServiceWorkerRegistration), + serviceWorkerDidUpdate({} as ServiceWorkerRegistration), ).checkingForUpdate, ).toBe(false); }); @@ -68,7 +73,7 @@ test('updateAvailable', () => { expect( reducers( { updateAvailable: false } as State, - didUpdate({} as ServiceWorkerRegistration), + serviceWorkerDidUpdate({} as ServiceWorkerRegistration), ).updateAvailable, ).toBe(true); }); @@ -102,7 +107,7 @@ test('readyForOfflineUse', () => { expect( reducers( { readyForOfflineUse: false } as State, - didSucceed({} as ServiceWorkerRegistration), + serviceWorkerDidSucceed({} as ServiceWorkerRegistration), ).readyForOfflineUse, ).toBe(true); }); diff --git a/src/app/reducers.ts b/src/app/reducers.ts index a9824f31..ec876d69 100644 --- a/src/app/reducers.ts +++ b/src/app/reducers.ts @@ -4,7 +4,10 @@ // Manages state the app in general. import { Reducer, combineReducers } from 'redux'; -import { didSucceed, didUpdate } from '../service-worker/actions'; +import { + serviceWorkerDidSucceed, + serviceWorkerDidUpdate, +} from '../service-worker/actions'; import { BeforeInstallPromptEvent } from '../utils/dom'; import { checkForUpdate, @@ -19,7 +22,7 @@ const serviceWorker: Reducer = ( state = null, action, ) => { - if (didSucceed.matches(action)) { + if (serviceWorkerDidSucceed.matches(action)) { return action.registration; } @@ -39,7 +42,7 @@ const checkingForUpdate: Reducer = (state = false, action) => { return state; } - if (didUpdate.matches(action)) { + if (serviceWorkerDidUpdate.matches(action)) { return false; } @@ -47,7 +50,7 @@ const checkingForUpdate: Reducer = (state = false, action) => { }; const updateAvailable: Reducer = (state = false, action) => { - if (didUpdate.matches(action)) { + if (serviceWorkerDidUpdate.matches(action)) { return true; } @@ -82,7 +85,7 @@ const promptingInstall: Reducer = (state = false, action) => { }; const readyForOfflineUse: Reducer = (state = false, action) => { - if (didSucceed.matches(action)) { + if (serviceWorkerDidSucceed.matches(action)) { return true; } diff --git a/src/index.tsx b/src/index.tsx index 03b54b4c..4d9e587e 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -16,7 +16,10 @@ import * as I18nToaster from './notifications/I18nToaster'; import { rootReducer } from './reducers'; import reportWebVitals from './reportWebVitals'; import rootSaga, { RootSagaContext } from './sagas'; -import { didSucceed, didUpdate } from './service-worker/actions'; +import { + serviceWorkerDidSucceed, + serviceWorkerDidUpdate, +} from './service-worker/actions'; import * as serviceWorkerRegistration from './serviceWorkerRegistration'; import { defaultTerminalContext } from './terminal/TerminalContext'; import ViewHeightSensor from './utils/ViewHeightSensor'; @@ -66,8 +69,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(didUpdate(r)), - onSuccess: (r) => store.dispatch(didSucceed(r)), + onUpdate: (r) => store.dispatch(serviceWorkerDidUpdate(r)), + onSuccess: (r) => store.dispatch(serviceWorkerDidSucceed(r)), }); // If you want to start measuring performance in your app, pass a function diff --git a/src/notifications/sagas.test.ts b/src/notifications/sagas.test.ts index 00ec21bf..eb7b0180 100644 --- a/src/notifications/sagas.test.ts +++ b/src/notifications/sagas.test.ts @@ -34,7 +34,10 @@ import { didFailToConnect as bootloaderDidFailToConnect, } from '../lwp3-bootloader/actions'; import { didCompile, didFailToCompile } from '../mpy/actions'; -import { didSucceed, didUpdate } from '../service-worker/actions'; +import { + serviceWorkerDidSucceed, + serviceWorkerDidUpdate, +} from '../service-worker/actions'; import { add } from './actions'; import { MessageId } from './i18n'; import notification from './sagas'; @@ -60,7 +63,7 @@ test.each([ didFailToCompile(['reason']), add('warning', 'message'), add('error', 'message', 'url'), - didUpdate({} as ServiceWorkerRegistration), + serviceWorkerDidUpdate({} as ServiceWorkerRegistration), didFailToFinish(FailToFinishReasonType.TimedOut), didFailToFinish( FailToFinishReasonType.BleError, @@ -122,7 +125,7 @@ test.each([ bleDidFailToConnect({ reason: BleDeviceFailToConnectReasonType.Canceled }), bootloaderDidFailToConnect(BootloaderConnectionFailureReason.Canceled), didFailToFinish(FailToFinishReasonType.FailedToConnect), - didSucceed({} as ServiceWorkerRegistration), + serviceWorkerDidSucceed({} as ServiceWorkerRegistration), didCheckForUpdate(true), bleDIServiceDidReceiveFirmwareRevision(firmwareVersion), didFailToSaveAs(new DOMException('test message', 'AbortError')), diff --git a/src/notifications/sagas.ts b/src/notifications/sagas.ts index d52909e9..0ff7df9a 100644 --- a/src/notifications/sagas.ts +++ b/src/notifications/sagas.ts @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2020 - 2022 The Pybricks Authors +// Copyright (c) 2020-2022 The Pybricks Authors // Saga for managing notifications (toasts) @@ -31,7 +31,7 @@ import { didFailToConnect as bootloaderDidFailToConnect, } from '../lwp3-bootloader/actions'; import { didCompile, didFailToCompile } from '../mpy/actions'; -import { didUpdate as serviceWorkerDidUpdate } from '../service-worker/actions'; +import { serviceWorkerDidUpdate as serviceWorkerDidUpdate } from '../service-worker/actions'; import { pythonVersionToSemver } from '../utils/version'; import NotificationAction from './NotificationAction'; import NotificationMessage from './NotificationMessage'; @@ -363,7 +363,7 @@ function* showServiceWorkerUpdate( function* showNoUpdateInfo(action: ReturnType): Generator { if (action.updateFound) { - // this will be handled by didUpdate action + // this will be handled by serviceWorkerDidUpdate action return; } diff --git a/src/service-worker/actions.ts b/src/service-worker/actions.ts index 3a719c13..b0e27394 100644 --- a/src/service-worker/actions.ts +++ b/src/service-worker/actions.ts @@ -1,14 +1,18 @@ // SPDX-License-Identifier: MIT -// Copyright (c) 2020,2022 The Pybricks Authors +// Copyright (c) 2020-2022 The Pybricks Authors import { createAction } from '../actions'; -export const didUpdate = createAction((registration: ServiceWorkerRegistration) => ({ - type: 'serviceWorker.action.didUpdate', - registration, -})); +export const serviceWorkerDidUpdate = createAction( + (registration: ServiceWorkerRegistration) => ({ + type: 'serviceWorker.action.didUpdate', + registration, + }), +); -export const didSucceed = createAction((registration: ServiceWorkerRegistration) => ({ - type: 'serviceWorker.action.didSucceed', - registration, -})); +export const serviceWorkerDidSucceed = createAction( + (registration: ServiceWorkerRegistration) => ({ + type: 'serviceWorker.action.didSucceed', + registration, + }), +);