actions: fix missed refactoring

Missed some renames when refactoring that weren't picked up locally
for some reason.
This commit is contained in:
David Lechner
2022-02-26 12:55:49 -06:00
parent a9f4eaa32d
commit 994540e263
3 changed files with 19 additions and 20 deletions
+7 -8
View File
@@ -10,7 +10,6 @@ import JSZip from 'jszip';
import { AsyncSaga } from '../../test';
import {
BootloaderConnectionFailureReason,
BootloaderProgramRequestAction,
checksumRequest,
checksumResponse,
connect,
@@ -160,7 +159,7 @@ describe('flashFirmware', () => {
programRequest(++id, 0x08005000 + offset, dummyPayload),
);
expect(
(action as BootloaderProgramRequestAction).payload.byteLength,
(action as ReturnType<typeof programRequest>).payload.byteLength,
).toBe(Math.min(14, totalFirmwareSize - offset));
saga.put(didRequest(id));
@@ -1092,7 +1091,7 @@ describe('flashFirmware', () => {
programRequest(++id, 0x08005000 + offset, dummyPayload),
);
expect(
(action as BootloaderProgramRequestAction).payload.byteLength,
(action as ReturnType<typeof programRequest>).payload.byteLength,
).toBe(Math.min(14, totalFirmwareSize - offset));
saga.put(didRequest(id));
@@ -1242,7 +1241,7 @@ describe('flashFirmware', () => {
programRequest(++id, 0x08005000 + offset, dummyPayload),
);
expect(
(action as BootloaderProgramRequestAction).payload.byteLength,
(action as ReturnType<typeof programRequest>).payload.byteLength,
).toBe(Math.min(14, totalFirmwareSize - offset));
saga.put(didRequest(id));
@@ -1395,7 +1394,7 @@ describe('flashFirmware', () => {
programRequest(++id, 0x08005000 + offset, dummyPayload),
);
expect(
(action as BootloaderProgramRequestAction).payload.byteLength,
(action as ReturnType<typeof programRequest>).payload.byteLength,
).toBe(Math.min(14, totalFirmwareSize - offset));
saga.put(didRequest(id));
@@ -1924,9 +1923,9 @@ describe('flashFirmware', () => {
expect(action).toEqual(
programRequest(++id, 0x08005000 + offset, dummyPayload),
);
expect((action as BootloaderProgramRequestAction).payload.byteLength).toBe(
Math.min(14, totalFirmwareSize - offset),
);
expect(
(action as ReturnType<typeof programRequest>).payload.byteLength,
).toBe(Math.min(14, totalFirmwareSize - offset));
saga.put(didRequest(id));
+4 -4
View File
@@ -7,8 +7,8 @@ import {
FirmwareReaderErrorCode,
firmwareVersion,
} from '@pybricks/firmware';
import { AnyAction } from 'redux';
import { AsyncSaga } from '../../test';
import { Action } from '../actions';
import { didCheckForUpdate } from '../app/actions';
import { bleDIServiceDidReceiveFirmwareRevision } from '../ble-device-info-service/actions';
import {
@@ -90,7 +90,7 @@ test.each([
fileStorageDidFailToInitialize(new Error('test error')),
fileStorageDidFailToReadFile('test.file', new Error('test error')),
fileStorageDidFailToWriteFile('test.file', new Error('test error')),
])('actions that should show notification: %o', async (action: Action) => {
])('actions that should show notification: %o', async (action: AnyAction) => {
const getToasts = jest.fn().mockReturnValue([]);
const show = jest.fn();
const dismiss = jest.fn();
@@ -122,7 +122,7 @@ test.each([
didCheckForUpdate(true),
bleDIServiceDidReceiveFirmwareRevision(firmwareVersion),
didFailToSaveAs(new DOMException('test message', 'AbortError')),
])('actions that should not show a notification: %o', async (action: Action) => {
])('actions that should not show a notification: %o', async (action: AnyAction) => {
const getToasts = jest.fn().mockReturnValue([]);
const show = jest.fn();
const dismiss = jest.fn();
@@ -149,7 +149,7 @@ test.each([
test.each([[didCompile(new Uint8Array()), MessageId.MpyError]])(
'actions that should close a notification: %o',
async (action: Action, key: string) => {
async (action: AnyAction, key: string) => {
const getToasts = jest.fn().mockReturnValue([]);
const show = jest.fn();
const dismiss = jest.fn();
+8 -8
View File
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
import { AnyAction } from 'redux';
import { END, MulticastChannel, Saga, Task, runSaga, stdChannel } from 'redux-saga';
import { Action } from '../src/actions';
import { RootState } from '../src/reducers';
type RecursivePartial<T> = {
@@ -10,9 +10,9 @@ type RecursivePartial<T> = {
};
export class AsyncSaga {
private channel: MulticastChannel<Action>;
private dispatches: (Action | END)[];
private takers: { put: (action: Action | END) => void }[];
private channel: MulticastChannel<AnyAction>;
private dispatches: (AnyAction | END)[];
private takers: { put: (action: AnyAction | END) => void }[];
private state: RecursivePartial<RootState>;
private task: Task;
@@ -43,18 +43,18 @@ export class AsyncSaga {
return this.dispatches.length;
}
public put(action: Action): void {
public put(action: AnyAction): void {
this.channel.put(action);
}
public take(): Promise<Action> {
public take(): Promise<AnyAction> {
const next = this.dispatches.shift();
if (next === undefined) {
// if there are no dispatches queued, then queue the taker to be
// completed later
return new Promise((resolve, reject) => {
this.takers.push({
put: (a: Action | END): void => {
put: (a: AnyAction | END): void => {
if (a.type === END.type) {
reject();
} else {
@@ -88,7 +88,7 @@ export class AsyncSaga {
}
}
private dispatch(action: Action | END): Action | END {
private dispatch(action: AnyAction | END): AnyAction | END {
const taker = this.takers.shift();
if (taker === undefined) {
// if there are no takers waiting, the queue the action