mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user