actions: simplify usage of Matchable

This removes use of the pseudo-internal toString() function and also
removes extraneous uses of ReturnType<>. Also, a new when() method
is added to simplify additional uses.
This commit is contained in:
David Lechner
2022-02-26 12:43:10 -06:00
parent 3cbfc4ca68
commit a9f4eaa32d
13 changed files with 125 additions and 142 deletions
+4 -8
View File
@@ -2,7 +2,6 @@
// Copyright (c) 2020-2022 The Pybricks Authors
import FileSaver from 'file-saver';
import { AnyAction } from 'redux';
import {
call,
put,
@@ -109,14 +108,11 @@ function* handleSetEditSession(action: ReturnType<typeof setEditSession>): Gener
yield* put(fileStorageReadFile(currentFileName));
const { result } = yield* race({
result: take<ReturnType<typeof fileStorageDidReadFile>>(
(a: AnyAction) =>
fileStorageDidReadFile.matches(a) && a.fileName === currentFileName,
result: take(
fileStorageDidReadFile.when((a) => a.fileName === currentFileName),
),
error: take<ReturnType<typeof fileStorageDidFailToReadFile>>(
(a: AnyAction) =>
fileStorageDidFailToReadFile.matches(a) &&
a.fileName === currentFileName,
error: take(
fileStorageDidFailToReadFile.when((a) => a.fileName === currentFileName),
),
});