This commit is contained in:
Nathan Bierema 2020-10-17 08:50:12 -04:00
parent 185e760ec3
commit 480b7a4201
7 changed files with 41 additions and 10 deletions

View File

@ -35,6 +35,7 @@ import {
SUBSCRIBE_SUCCESS,
UNSUBSCRIBE,
} from '../constants/socketActionTypes';
import { Action } from 'redux';
let monitorReducer;
let monitorProps = {};
@ -65,7 +66,18 @@ export function changeTheme(data: ChangeThemeData): ChangeThemeAction {
return { type: CHANGE_THEME, ...data.formData };
}
export function liftedDispatch(action) {
interface MonitorActionAction {
type: typeof MONITOR_ACTION;
action: Action<unknown>;
}
interface LiftedActionAction {
type: typeof LIFTED_ACTION;
message: 'DISPATCH';
action: Action<unknown>;
}
export function liftedDispatch(
action: Action<unknown>
): MonitorActionAction | LiftedActionAction {
if (action.type[0] === '@') {
if (action.type === '@@INIT_MONITOR') {
monitorReducer = action.update;
@ -289,6 +301,8 @@ interface UnsubscribeAction {
export type StoreAction =
| ChangeSectionAction
| ChangeThemeAction
| MonitorActionAction
| LiftedActionAction
| SelectInstanceAction
| SelectMonitorAction
| UpdateMonitorStateAction

View File

@ -1,16 +1,22 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { ActionCreators } from 'redux-devtools-instrument';
import { ActionCreators, LiftedAction } from 'redux-devtools-instrument';
import { Button, Toolbar, Divider } from 'devui';
import RecordButton from './buttons/RecordButton';
import PersistButton from './buttons/PersistButton';
import LockButton from './buttons/LockButton';
import InstanceSelector from './InstanceSelector';
import SyncButton from './buttons/SyncButton';
import { Action } from 'redux';
// eslint-disable-next-line @typescript-eslint/unbound-method
const { reset, rollback, commit, sweep } = ActionCreators;
export default class TopButtons extends Component {
interface Props {
dispatch: (action: LiftedAction<unknown, Action<unknown>, unknown>) => void;
}
export default class TopButtons extends Component<Props> {
static propTypes = {
// shouldSync: PropTypes.bool,
liftedState: PropTypes.object.isRequired,
@ -18,7 +24,7 @@ export default class TopButtons extends Component {
options: PropTypes.object.isRequired,
};
shouldComponentUpdate(nextProps) {
shouldComponentUpdate(nextProps: Props) {
return (
nextProps.options !== this.props.options ||
nextProps.liftedState !== this.props.liftedState

View File

@ -1,6 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { connect, ResolveThunks } from 'react-redux';
import { Container } from 'devui';
import SliderMonitor from './monitors/Slider';
import { liftedDispatch as liftedDispatchAction, getReport } from '../actions';
@ -11,7 +11,11 @@ import TopButtons from '../components/TopButtons';
import BottomButtons from '../components/BottomButtons';
import { StoreState } from '../reducers';
class Actions extends Component {
type StateProps = ReturnType<typeof mapStateToProps>;
type DispatchProps = ResolveThunks<typeof actionCreators>;
type Props = StateProps & DispatchProps;
class Actions extends Component<Props> {
render() {
const {
monitor,

View File

@ -2,10 +2,10 @@ import { combineReducers } from 'redux';
import section, { SectionState } from './section';
import connection, { ConnectionState } from './connection';
import socket, { SocketState } from './socket';
import monitor from './monitor';
import monitor, { MonitorState } from './monitor';
import notification, { NotificationState } from './notification';
import instances from './instances';
import reports from './reports';
import instances, { InstancesState } from './instances';
import reports, { ReportsState } from './reports';
import theme, { ThemeState } from './theme';
import { StoreAction } from '../actions';
@ -14,6 +14,9 @@ export interface StoreState {
readonly theme: ThemeState;
readonly connection: ConnectionState;
readonly socket: SocketState;
readonly monitor: MonitorState;
readonly instances: InstancesState;
readonly reports: ReportsState;
readonly notification: NotificationState;
}

View File

@ -12,7 +12,7 @@ import parseJSON from '../utils/parseJSON';
import { recompute } from '../utils/updateState';
import { StoreAction } from '../actions';
interface InstancesState {
export interface InstancesState {
sync: boolean;
persisted?: boolean;
}

View File

@ -7,6 +7,8 @@ import {
} from '../constants/actionTypes';
import { StoreAction } from '../actions';
export interface MonitorState {}
const initialState = {
selected: 'InspectorMonitor',
monitorState: undefined,

View File

@ -3,6 +3,8 @@ import {
} from '../constants/actionTypes';
import { StoreAction } from '../actions';
export interface ReportsState {}
const initialState = {
data: [],
};