Add common top-level Action type

This makes for better type inference.
This commit is contained in:
David Lechner
2020-05-26 21:20:08 -05:00
committed by David Lechner
parent 6713afe198
commit 6e4b22f841
15 changed files with 90 additions and 25 deletions
+5 -6
View File
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
import { Action, Dispatch } from 'redux';
import { Action, Dispatch } from '../actions';
import {
BootloaderConnectionActionType,
BootloaderConnectionSendAction,
didCancel,
didConnect,
didDisconnect,
@@ -130,11 +130,10 @@ async function send(action: Action, dispatch: Dispatch): Promise<void> {
if (!char) {
throw Error('Not connected');
}
const sendAction = action as BootloaderConnectionSendAction;
if (sendAction.withResponse) {
await char.xWriteValueWithResponse(sendAction.data);
if (action.withResponse) {
await char.xWriteValueWithResponse(action.data);
} else {
await char.xWriteValueWithoutResponse(sendAction.data);
await char.xWriteValueWithoutResponse(action.data);
}
dispatch(didSend());
} catch (err) {
+1 -1
View File
@@ -2,7 +2,7 @@
// Copyright (c) 2020 The Pybricks Authors
import * as FileSaver from 'file-saver';
import { Action, Dispatch } from 'redux';
import { Action, Dispatch } from '../actions';
import { EditorActionType, EditorOpenAction } from '../actions/editor';
import { RootState } from '../reducers';
import { combineServices } from '.';
+2 -1
View File
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
import { Action, Dispatch, Middleware } from 'redux';
import { Middleware } from 'redux';
import { Action, Dispatch } from '../actions';
import { RootState } from '../reducers';
import bootloader from './bootloader';
import editor from './editor';