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

View File

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

View File

@ -1,6 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect, ResolveThunks } from 'react-redux';
import { Container } from 'devui'; import { Container } from 'devui';
import SliderMonitor from './monitors/Slider'; import SliderMonitor from './monitors/Slider';
import { liftedDispatch as liftedDispatchAction, getReport } from '../actions'; import { liftedDispatch as liftedDispatchAction, getReport } from '../actions';
@ -11,7 +11,11 @@ import TopButtons from '../components/TopButtons';
import BottomButtons from '../components/BottomButtons'; import BottomButtons from '../components/BottomButtons';
import { StoreState } from '../reducers'; 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() { render() {
const { const {
monitor, monitor,

View File

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

View File

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

View File

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

View File

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