actions: added typed useDispatch() hook

This commit is contained in:
David Lechner
2021-12-27 18:01:51 -06:00
parent 8d26f768bf
commit 54ec447061
12 changed files with 18 additions and 12 deletions
+7 -1
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
// Copyright (c) 2020-2021 The Pybricks Authors
import { useDispatch as useReduxDispatch } from 'react-redux';
import { Dispatch as ReduxDispatch } from 'redux';
import { AppAction } from './app/actions';
import { BleDIServiceAction } from './ble-device-info-service/actions';
@@ -60,3 +61,8 @@ export type Action =
* Dispatch function.
*/
export type Dispatch = ReduxDispatch<Action>;
/**
* Typed version of Redux useDispatch() hook.
*/
export const useDispatch = (): Dispatch => useReduxDispatch<Dispatch>();
+1 -1
View File
@@ -3,8 +3,8 @@
import { Classes } from '@blueprintjs/core';
import React, { useEffect, useState } from 'react';
import { useDispatch } from 'react-redux';
import SplitterLayout from 'react-splitter-layout';
import { useDispatch } from '../actions';
import Editor from '../editor/Editor';
import { useSelector } from '../reducers';
import { toggleBoolean } from '../settings/actions';
+1 -1
View File
@@ -12,8 +12,8 @@ import tomorrowNightEightiesTheme from 'monaco-themes/themes/Tomorrow-Night-Eigh
import xcodeTheme from 'monaco-themes/themes/Xcode_default.json';
import React, { useEffect, useRef } from 'react';
import MonacoEditor, { monaco } from 'react-monaco-editor';
import { useDispatch } from 'react-redux';
import { IDisposable } from 'xterm';
import { useDispatch } from '../actions';
import { compile } from '../mpy/actions';
import { useSelector } from '../reducers';
import { toggleBoolean } from '../settings/actions';
+1 -1
View File
@@ -2,7 +2,7 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import React from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch } from '../actions';
import * as notificationActions from '../notifications/actions';
import { useSelector } from '../reducers';
import OpenFileButton, { OpenFileButtonProps } from '../toolbar/OpenFileButton';
+1 -1
View File
@@ -2,7 +2,7 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import React from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch } from '../actions';
import * as editorActions from '../editor/actions';
import { useSelector } from '../reducers';
import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton';
+1 -1
View File
@@ -2,7 +2,7 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import React from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch } from '../actions';
import { BleConnectionState } from '../ble/reducers';
import { BootloaderConnectionState } from '../lwp3-bootloader/reducers';
import * as notificationActions from '../notifications/actions';
+1 -1
View File
@@ -2,7 +2,7 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import React from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch } from '../actions';
import { toggleBluetooth } from '../ble/actions';
import { BleConnectionState } from '../ble/reducers';
import { BootloaderConnectionState } from '../lwp3-bootloader/reducers';
+1 -1
View File
@@ -2,7 +2,7 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import React from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch } from '../actions';
import { useSelector } from '../reducers';
import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton';
import { TooltipId } from '../toolbar/i18n';
+1 -1
View File
@@ -2,7 +2,7 @@
// Copyright (c) 2020-2021 The Pybricks Authors
import React from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch } from '../actions';
import { useSelector } from '../reducers';
import ActionButton, { ActionButtonProps } from '../toolbar/ActionButton';
import { TooltipId } from '../toolbar/i18n';
+1 -1
View File
@@ -14,7 +14,7 @@ import {
} from '@blueprintjs/core';
import { useI18n } from '@shopify/react-i18n';
import React from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch } from '../actions';
import { appName } from '../app/constants';
import { useSelector } from '../reducers';
import { fetchList, select } from './actions';
+1 -1
View File
@@ -19,8 +19,8 @@ import {
import { Tooltip2 } from '@blueprintjs/popover2';
import { useI18n } from '@shopify/react-i18n';
import React, { useMemo, useState } from 'react';
import { useDispatch } from 'react-redux';
import AboutDialog from '../about/AboutDialog';
import { useDispatch } from '../actions';
import { checkForUpdate, installPrompt, reload } from '../app/actions';
import {
pybricksBugReportsUrl,
+1 -1
View File
@@ -5,9 +5,9 @@ import { Menu, MenuDivider, MenuItem, ResizeSensor } from '@blueprintjs/core';
import { ContextMenu2, ContextMenu2ContentProps } from '@blueprintjs/popover2';
import { useI18n } from '@shopify/react-i18n';
import React, { useContext, useEffect, useMemo, useRef } from 'react';
import { useDispatch } from 'react-redux';
import { Terminal as XTerm } from 'xterm';
import { FitAddon } from 'xterm-addon-fit';
import { useDispatch } from '../actions';
import { useSelector } from '../reducers';
import { isMacOS } from '../utils/os';
import { TerminalContext } from './TerminalContext';