2022-05-16 00:47:09 +03:00
|
|
|
import React, { CSSProperties, useRef } from 'react';
|
2020-08-08 22:46:01 +03:00
|
|
|
import { connect } from 'react-redux';
|
2021-09-18 17:00:58 +03:00
|
|
|
import { Button, Toolbar, Spacer } from '@redux-devtools/ui';
|
2021-09-25 07:54:14 +03:00
|
|
|
import pkg from '@redux-devtools/inspector-monitor-test-tab/package.json';
|
2022-05-16 00:47:09 +03:00
|
|
|
import { useLocation } from 'react-router-dom';
|
2020-09-13 07:02:24 +03:00
|
|
|
import getOptions from './getOptions';
|
|
|
|
import { DemoAppState } from './reducers';
|
|
|
|
import {
|
|
|
|
AddFunctionAction,
|
|
|
|
AddHugeObjectAction,
|
|
|
|
AddImmutableMapAction,
|
|
|
|
AddIteratorAction,
|
|
|
|
AddRecursiveAction,
|
|
|
|
AddSymbolAction,
|
|
|
|
ChangeImmutableNestedAction,
|
|
|
|
ChangeNestedAction,
|
|
|
|
HugePayloadAction,
|
|
|
|
IncrementAction,
|
|
|
|
PopAction,
|
|
|
|
PushAction,
|
|
|
|
PushHugeArrayAction,
|
|
|
|
ReplaceAction,
|
|
|
|
ShuffleArrayAction,
|
|
|
|
TimeoutUpdateAction,
|
|
|
|
ToggleTimeoutUpdateAction,
|
|
|
|
} from './reducers';
|
2020-08-08 22:46:01 +03:00
|
|
|
|
2020-09-13 07:02:24 +03:00
|
|
|
const styles: {
|
|
|
|
wrapper: CSSProperties;
|
|
|
|
muted: CSSProperties;
|
|
|
|
link: CSSProperties;
|
|
|
|
} = {
|
2020-08-08 22:46:01 +03:00
|
|
|
wrapper: {
|
|
|
|
height: '100vh',
|
|
|
|
width: '450px',
|
|
|
|
margin: 'auto',
|
2020-08-08 23:26:39 +03:00
|
|
|
textAlign: 'center',
|
2020-08-08 22:46:01 +03:00
|
|
|
},
|
|
|
|
muted: {
|
2020-08-08 23:26:39 +03:00
|
|
|
color: '#CCCCCC',
|
2020-08-08 22:46:01 +03:00
|
|
|
},
|
|
|
|
link: {
|
|
|
|
margin: '0 0.5rem',
|
|
|
|
cursor: 'pointer',
|
2020-08-08 23:26:39 +03:00
|
|
|
display: 'block',
|
|
|
|
},
|
2020-08-08 22:46:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const ROOT = '/'; // process.env.NODE_ENV === 'production' ? '/' : '/';
|
|
|
|
|
2020-09-13 07:02:24 +03:00
|
|
|
interface Props
|
|
|
|
extends Omit<DemoAppState, 'addFunction' | 'addSymbol' | 'shuffleArray'> {
|
|
|
|
toggleTimeoutUpdate: (timeoutUpdateEnabled: boolean) => void;
|
|
|
|
timeoutUpdate: () => void;
|
|
|
|
increment: () => void;
|
|
|
|
push: () => void;
|
|
|
|
pop: () => void;
|
|
|
|
replace: () => void;
|
|
|
|
changeNested: () => void;
|
|
|
|
pushHugeArray: () => void;
|
|
|
|
addIterator: () => void;
|
|
|
|
addHugeObject: () => void;
|
|
|
|
addRecursive: () => void;
|
|
|
|
addImmutableMap: () => void;
|
|
|
|
changeImmutableNested: () => void;
|
|
|
|
hugePayload: () => void;
|
|
|
|
addFunction: () => void;
|
|
|
|
addSymbol: () => void;
|
|
|
|
shuffleArray: () => void;
|
|
|
|
}
|
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
function DemoApp(props: Props) {
|
|
|
|
const timeout = useRef<number | undefined>();
|
|
|
|
const location = useLocation();
|
2020-09-13 07:02:24 +03:00
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
const options = getOptions(location);
|
2020-08-08 22:46:01 +03:00
|
|
|
|
2022-05-16 00:47:09 +03:00
|
|
|
const toggleTimeoutUpdate = () => {
|
|
|
|
const enabled = !props.timeoutUpdateEnabled;
|
|
|
|
props.toggleTimeoutUpdate(enabled);
|
2020-08-08 22:46:01 +03:00
|
|
|
|
|
|
|
if (enabled) {
|
2022-05-16 00:47:09 +03:00
|
|
|
timeout.current = window.setInterval(props.timeoutUpdate, 1000);
|
2020-08-08 22:46:01 +03:00
|
|
|
} else {
|
2022-05-16 00:47:09 +03:00
|
|
|
clearTimeout(timeout.current);
|
2020-08-08 22:46:01 +03:00
|
|
|
}
|
|
|
|
};
|
2022-05-16 00:47:09 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={styles.wrapper}>
|
|
|
|
<h3>{pkg.name || <span style={styles.muted}>Package Name</span>}</h3>
|
|
|
|
<h5>
|
|
|
|
{pkg.description || (
|
|
|
|
<span style={styles.muted}>Package Description</span>
|
|
|
|
)}
|
|
|
|
</h5>
|
|
|
|
<Toolbar>
|
|
|
|
<Spacer />
|
|
|
|
<Button onClick={props.increment}>Increment</Button>
|
|
|
|
<Button onClick={props.push}>Push</Button>
|
|
|
|
<Button onClick={props.pop}>Pop</Button>
|
|
|
|
<Button onClick={props.replace}>Replace</Button>
|
|
|
|
<Button onClick={props.changeNested}>Change Nested</Button>
|
|
|
|
<Spacer />
|
|
|
|
</Toolbar>
|
|
|
|
<Toolbar>
|
|
|
|
<Spacer />
|
|
|
|
<Button onClick={props.pushHugeArray}>Push Huge Array</Button>
|
|
|
|
<Button onClick={props.addHugeObject}>Add Huge Object</Button>
|
|
|
|
<Button onClick={props.hugePayload}>Huge Payload</Button>
|
|
|
|
<Spacer />
|
|
|
|
</Toolbar>
|
|
|
|
<Toolbar>
|
|
|
|
<Spacer />
|
|
|
|
<Button onClick={props.addIterator}>Add Iterator</Button>
|
|
|
|
<Button onClick={props.addImmutableMap}>Add Immutable Map</Button>
|
|
|
|
<Button onClick={props.changeImmutableNested}>
|
|
|
|
Change Immutable Nested
|
|
|
|
</Button>
|
|
|
|
<Spacer />
|
|
|
|
</Toolbar>
|
|
|
|
<Toolbar>
|
|
|
|
<Spacer />
|
|
|
|
<Button onClick={props.addRecursive}>Add Recursive</Button>
|
|
|
|
<Button onClick={props.addFunction}>Add Function</Button>
|
|
|
|
<Button onClick={props.addSymbol}>Add Symbol</Button>
|
|
|
|
<Spacer />
|
|
|
|
</Toolbar>
|
|
|
|
<Toolbar>
|
|
|
|
<Spacer />
|
|
|
|
<Button onClick={toggleTimeoutUpdate}>
|
|
|
|
Timeout Update {props.timeoutUpdateEnabled ? 'On' : 'Off'}
|
|
|
|
</Button>
|
|
|
|
<Button onClick={props.shuffleArray}>Shuffle Array</Button>
|
|
|
|
<Spacer />
|
|
|
|
</Toolbar>
|
|
|
|
<div>
|
|
|
|
{options.useExtension ? (
|
|
|
|
<a href={`${ROOT}`} style={styles.link}>
|
|
|
|
Disable browser extension
|
|
|
|
</a>
|
|
|
|
) : (
|
|
|
|
<a href={`${ROOT}?ext`} style={styles.link}>
|
|
|
|
Use browser extension
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2020-08-08 22:46:01 +03:00
|
|
|
}
|
|
|
|
|
2020-09-13 07:02:24 +03:00
|
|
|
export default connect((state: DemoAppState) => state, {
|
|
|
|
toggleTimeoutUpdate: (
|
2023-07-12 21:03:20 +03:00
|
|
|
timeoutUpdateEnabled: boolean,
|
2020-09-13 07:02:24 +03:00
|
|
|
): ToggleTimeoutUpdateAction => ({
|
2020-08-08 22:46:01 +03:00
|
|
|
type: 'TOGGLE_TIMEOUT_UPDATE',
|
2020-08-08 23:26:39 +03:00
|
|
|
timeoutUpdateEnabled,
|
2020-08-08 22:46:01 +03:00
|
|
|
}),
|
2020-09-13 07:02:24 +03:00
|
|
|
timeoutUpdate: (): TimeoutUpdateAction => ({ type: 'TIMEOUT_UPDATE' }),
|
|
|
|
increment: (): IncrementAction => ({ type: 'INCREMENT' }),
|
|
|
|
push: (): PushAction => ({ type: 'PUSH' }),
|
|
|
|
pop: (): PopAction => ({ type: 'POP' }),
|
|
|
|
replace: (): ReplaceAction => ({ type: 'REPLACE' }),
|
|
|
|
changeNested: (): ChangeNestedAction => ({ type: 'CHANGE_NESTED' }),
|
|
|
|
pushHugeArray: (): PushHugeArrayAction => ({ type: 'PUSH_HUGE_ARRAY' }),
|
|
|
|
addIterator: (): AddIteratorAction => ({ type: 'ADD_ITERATOR' }),
|
|
|
|
addHugeObject: (): AddHugeObjectAction => ({ type: 'ADD_HUGE_OBJECT' }),
|
|
|
|
addRecursive: (): AddRecursiveAction => ({ type: 'ADD_RECURSIVE' }),
|
|
|
|
addImmutableMap: (): AddImmutableMapAction => ({ type: 'ADD_IMMUTABLE_MAP' }),
|
|
|
|
changeImmutableNested: (): ChangeImmutableNestedAction => ({
|
|
|
|
type: 'CHANGE_IMMUTABLE_NESTED',
|
|
|
|
}),
|
|
|
|
hugePayload: (): HugePayloadAction => ({
|
2020-08-08 22:46:01 +03:00
|
|
|
type: 'HUGE_PAYLOAD',
|
2020-08-08 23:26:39 +03:00
|
|
|
payload: Array.from({ length: 10000 }).map((_, i) => i),
|
2020-08-08 22:46:01 +03:00
|
|
|
}),
|
2020-09-13 07:02:24 +03:00
|
|
|
addFunction: (): AddFunctionAction => ({ type: 'ADD_FUNCTION' }),
|
|
|
|
addSymbol: (): AddSymbolAction => ({ type: 'ADD_SYMBOL' }),
|
|
|
|
shuffleArray: (): ShuffleArrayAction => ({ type: 'SHUFFLE_ARRAY' }),
|
2022-05-16 00:47:09 +03:00
|
|
|
})(DemoApp);
|