This commit is contained in:
Nathan Bierema 2020-10-25 16:14:33 -04:00
parent 2bfeb49b43
commit 5b6a0adbfd
11 changed files with 48 additions and 37 deletions

View File

@ -18,7 +18,7 @@ module.exports = {
},
},
{
files: ['webpack.config.umd.ts'],
files: ['webpack.config.ts', 'webpack.config.umd.ts'],
extends: '../../eslintrc.ts.base.json',
parserOptions: {
tsconfigRootDir: __dirname,

View File

@ -502,7 +502,7 @@ export interface EmitAction {
interface ListRequest {
type: 'list';
data: Data;
data: Data[];
}
interface AddRequest {
type: 'add';
@ -513,7 +513,7 @@ interface RemoveRequest {
data: Data;
id: unknown;
}
type UpdateReportsRequest = ListRequest | AddRequest | RemoveRequest;
export type UpdateReportsRequest = ListRequest | AddRequest | RemoveRequest;
interface UpdateReportsAction {
type: typeof UPDATE_REPORTS;
request: UpdateReportsRequest;

View File

@ -1,5 +1,4 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect, ResolveThunks } from 'react-redux';
import { Select } from 'devui';
import { selectInstance } from '../actions';
@ -10,12 +9,6 @@ type DispatchProps = ResolveThunks<typeof actionCreators>;
type Props = StateProps & DispatchProps;
class InstanceSelector extends Component<Props> {
static propTypes = {
selected: PropTypes.string,
instances: PropTypes.object.isRequired,
onSelect: PropTypes.func.isRequired,
};
select?: { readonly value: string; readonly label: string }[];
render() {
@ -24,8 +17,7 @@ class InstanceSelector extends Component<Props> {
let name;
Object.keys(instances).forEach((key) => {
name = instances[key].name;
if (name !== undefined)
this.select!.push({ value: key, label: instances[key].name });
if (name !== undefined) this.select!.push({ value: key, label: name });
});
return (

View File

@ -23,8 +23,7 @@ class Settings extends Component<{}, State> {
return (
// eslint-disable-next-line @typescript-eslint/ban-types
<Tabs<{}>
toRight
tabs={this.tabs}
tabs={this.tabs as any}
selected={this.state.selected}
onClick={this.handleSelect}
/>

View File

@ -21,7 +21,6 @@ class LockButton extends Component<Props> {
render() {
return (
<Button
toolbar
tooltipPosition="bottom"
disabled={this.props.disabled}
mark={this.props.persisted && 'base0D'}

View File

@ -21,6 +21,7 @@ import {
LiftedActionAction,
Request,
DispatchAction,
UpdateReportsRequest,
} from '../actions';
import { nonReduxDispatch } from '../utils/monitorActions';
import { StoreState } from '../reducers';
@ -136,7 +137,7 @@ function subscribe(
const channel = socket.subscribe(channelName);
if (subscription === UPDATE_STATE) channel.watch(monitoring);
else {
const watcher = (request: Request) => {
const watcher = (request: UpdateReportsRequest) => {
store.dispatch({ type: subscription, request });
};
channel.watch(watcher);

View File

@ -107,13 +107,14 @@ function updateState(
let newState;
const liftedState = state[id] || state.default;
const action = (request.action && parseJSON(request.action, serialize)) || {};
const action = ((request.action && parseJSON(request.action, serialize)) ||
{}) as PerformAction<Action<unknown>>;
switch (request.type) {
case 'INIT':
newState = recompute(state.default, payload, {
action: { type: '@@INIT' },
timestamp: (action as { timestamp?: unknown }).timestamp || Date.now(),
timestamp: (action as { timestamp?: number }).timestamp || Date.now(),
});
break;
case 'ACTION': {
@ -301,7 +302,10 @@ function init(
};
}
export default function instances(state = initialState, action: StoreAction) {
export default function instances(
state = initialState,
action: StoreAction
): InstancesState {
switch (action.type) {
case UPDATE_STATE: {
const { request } = action;
@ -360,7 +364,7 @@ export default function instances(state = initialState, action: StoreAction) {
...state,
states: {
...state.states,
[id]: parseJSON(action.state),
[id]: parseJSON(action.state) as State,
},
};
}

View File

@ -15,7 +15,10 @@ const initialState: ReportsState = {
data: [],
};
export default function reports(state = initialState, action: StoreAction) {
export default function reports(
state = initialState,
action: StoreAction
): ReportsState {
/* if (action.type === GET_REPORT_SUCCESS) {
const id = action.data.id;
return {
@ -28,17 +31,16 @@ export default function reports(state = initialState, action: StoreAction) {
return state;
const request = action.request;
const data = request.data;
switch (request.type) {
case 'list':
return {
...state,
data,
data: request.data,
};
case 'add':
return {
...state,
data: [...state.data, data],
data: [...state.data, request.data],
};
case 'remove':
return {

View File

@ -14,7 +14,10 @@ function replacer(key: string, value: unknown) {
return value;
}
export default function stringifyJSON(data: unknown, serialize: boolean) {
export default function stringifyJSON(
data: unknown,
serialize: boolean | undefined
) {
return serialize
? jsan.stringify(data, replacer, (null as unknown) as undefined, true)
: jsan.stringify(data);

View File

@ -6,7 +6,9 @@ import { PerformAction } from 'redux-devtools-instrument';
export function recompute(
previousLiftedState: State,
storeState: State,
action: Action<unknown>,
action:
| PerformAction<Action<unknown>>
| { action: Action<unknown>; timestamp?: number; stack?: string },
nextActionId = 1,
maxAge?: number,
isExcess?: boolean
@ -22,15 +24,15 @@ export function recompute(
}
liftedState.stagedActionIds = [...liftedState.stagedActionIds, actionId];
liftedState.actionsById = { ...liftedState.actionsById };
if (action.type === 'PERFORM_ACTION') {
if ((action as PerformAction<Action<unknown>>).type === 'PERFORM_ACTION') {
liftedState.actionsById[actionId] = action as PerformAction<
Action<unknown>
>;
} else {
liftedState.actionsById[actionId] = {
action: (action as any).action || action,
timestamp: (action as any).timestamp || Date.now(),
stack: (action as any).stack,
action: action.action || action,
timestamp: action.timestamp || Date.now(),
stack: action.stack,
type: 'PERFORM_ACTION',
};
}

View File

@ -1,14 +1,15 @@
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
import * as path from 'path';
import * as webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
module.exports = (env = {}) => ({
module.exports = (env: { development?: boolean; platform?: string } = {}) => ({
mode: env.development ? 'development' : 'production',
entry: {
app: './index.js',
app: './index',
},
output: {
path: path.resolve(__dirname, 'build/' + env.platform),
path: path.resolve(__dirname, `build/${env.platform as string}`),
publicPath: '',
filename: 'js/[name].js',
sourceMapFilename: 'js/[name].map',
@ -16,7 +17,7 @@ module.exports = (env = {}) => ({
module: {
rules: [
{
test: /\.js$/,
test: /\.(js|ts)x?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
@ -44,6 +45,9 @@ module.exports = (env = {}) => ({
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
@ -56,6 +60,11 @@ module.exports = (env = {}) => ({
new HtmlWebpackPlugin({
template: 'assets/index.html',
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: 'tsconfig.json',
},
}),
],
optimization: {
minimize: false,