mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
service-worker: rename actions
This adds a prefix to the actions so that we won't have to use aliases.
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
+8
-5
@@ -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<ServiceWorkerRegistration | null> = (
|
||||
state = null,
|
||||
action,
|
||||
) => {
|
||||
if (didSucceed.matches(action)) {
|
||||
if (serviceWorkerDidSucceed.matches(action)) {
|
||||
return action.registration;
|
||||
}
|
||||
|
||||
@@ -39,7 +42,7 @@ const checkingForUpdate: Reducer<boolean> = (state = false, action) => {
|
||||
return state;
|
||||
}
|
||||
|
||||
if (didUpdate.matches(action)) {
|
||||
if (serviceWorkerDidUpdate.matches(action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -47,7 +50,7 @@ const checkingForUpdate: Reducer<boolean> = (state = false, action) => {
|
||||
};
|
||||
|
||||
const updateAvailable: Reducer<boolean> = (state = false, action) => {
|
||||
if (didUpdate.matches(action)) {
|
||||
if (serviceWorkerDidUpdate.matches(action)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -82,7 +85,7 @@ const promptingInstall: Reducer<boolean> = (state = false, action) => {
|
||||
};
|
||||
|
||||
const readyForOfflineUse: Reducer<boolean> = (state = false, action) => {
|
||||
if (didSucceed.matches(action)) {
|
||||
if (serviceWorkerDidSucceed.matches(action)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -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
|
||||
|
||||
@@ -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')),
|
||||
|
||||
@@ -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<typeof didCheckForUpdate>): Generator {
|
||||
if (action.updateFound) {
|
||||
// this will be handled by didUpdate action
|
||||
// this will be handled by serviceWorkerDidUpdate action
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user