This commit is contained in:
Nathan Bierema 2020-08-09 18:07:32 -04:00
parent 6e23e538ce
commit 0903e75b9c
4 changed files with 19 additions and 24 deletions

View File

@ -1,3 +0,0 @@
{
"import": true
}

View File

@ -85,7 +85,7 @@ function buildUrl(options) {
class DemoApp extends React.Component { class DemoApp extends React.Component {
render() { render() {
const options = getOptions(); const options = getOptions(this.props.router.location);
return ( return (
<div style={styles.wrapper}> <div style={styles.wrapper}>
@ -193,7 +193,7 @@ class DemoApp extends React.Component {
<div style={styles.links}> <div style={styles.links}>
<a onClick={this.toggleExtension} style={styles.link}> <a onClick={this.toggleExtension} style={styles.link}>
{(options.useExtension ? 'Disable' : 'Enable') + {(options.useExtension ? 'Disable' : 'Enable') +
' Chrome Extension'} ' Chrome Extension (will reload this page)'}
</a> </a>
<a onClick={this.toggleImmutableSupport} style={styles.link}> <a onClick={this.toggleImmutableSupport} style={styles.link}>
{(options.supportImmutable ? 'Disable' : 'Enable') + {(options.supportImmutable ? 'Disable' : 'Enable') +
@ -205,15 +205,16 @@ class DemoApp extends React.Component {
} }
toggleExtension = () => { toggleExtension = () => {
const options = getOptions(); const options = getOptions(this.props.router.location);
this.props.pushRoute( window.location.href = buildUrl({
buildUrl({ ...options, useExtension: !options.useExtension }) ...options,
); useExtension: !options.useExtension,
});
}; };
toggleImmutableSupport = () => { toggleImmutableSupport = () => {
const options = getOptions(); const options = getOptions(this.props.router.location);
this.props.pushRoute( this.props.pushRoute(
buildUrl({ ...options, supportImmutable: !options.supportImmutable }) buildUrl({ ...options, supportImmutable: !options.supportImmutable })
@ -221,7 +222,7 @@ class DemoApp extends React.Component {
}; };
toggleTheme = () => { toggleTheme = () => {
const options = getOptions(); const options = getOptions(this.props.router.location);
this.props.pushRoute(buildUrl({ ...options, dark: !options.dark })); this.props.pushRoute(buildUrl({ ...options, dark: !options.dark }));
}; };

View File

@ -1,11 +1,11 @@
export default function getOptions() { export default function getOptions(location) {
return { return {
useExtension: window.location.search.indexOf('ext') !== -1, useExtension: location.search.indexOf('ext') !== -1,
supportImmutable: window.location.search.indexOf('immutable') !== -1, supportImmutable: location.search.indexOf('immutable') !== -1,
theme: do { theme: do {
const match = window.location.search.match(/theme=([^&]+)/); const match = location.search.match(/theme=([^&]+)/);
match ? match[1] : 'inspector'; match ? match[1] : 'inspector';
}, },
dark: window.location.search.indexOf('dark') !== -1, dark: location.search.indexOf('dark') !== -1,
}; };
} }

View File

@ -43,13 +43,10 @@ const getDevTools = ({ location }) =>
changeMonitorKey="ctrl-m" changeMonitorKey="ctrl-m"
> >
<DevtoolsInspector <DevtoolsInspector
theme={do { theme={getOptions(location).theme}
const match = window.location.search.match(/theme=([^&]+)/);
match ? match[1] : 'inspector';
}}
shouldPersistState shouldPersistState
invertTheme={location.search.indexOf('dark') === -1} invertTheme={getOptions(location).dark}
supportImmutable={location.search.indexOf('immutable') !== -1} supportImmutable={getOptions(location).supportImmutable}
tabs={(defaultTabs) => [ tabs={(defaultTabs) => [
{ {
name: 'Custom Tab', name: 'Custom Tab',
@ -64,13 +61,13 @@ const getDevTools = ({ location }) =>
const ROOT = const ROOT =
process.env.NODE_ENV === 'production' ? '/redux-devtools-inspector/' : '/'; process.env.NODE_ENV === 'production' ? '/redux-devtools-inspector/' : '/';
const DevTools = getDevTools(getOptions()); const DevTools = getDevTools({ location: window.location });
const history = createBrowserHistory(); const history = createBrowserHistory();
const useDevtoolsExtension = const useDevtoolsExtension =
!!window.__REDUX_DEVTOOLS_EXTENSION__ && !!window.__REDUX_DEVTOOLS_EXTENSION__ &&
window.location.search.indexOf('ext') !== -1; getOptions(window.location).useExtension;
const enhancer = compose( const enhancer = compose(
applyMiddleware(logger, routerMiddleware(history)), applyMiddleware(logger, routerMiddleware(history)),