mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-27 08:30:02 +03:00
Merge e993425245
into b1367c61d4
This commit is contained in:
commit
851ea112d4
|
@ -1,6 +1,12 @@
|
||||||
import React, { PropTypes, findDOMNode } from 'react';
|
import React, { PropTypes, findDOMNode } from 'react';
|
||||||
import LogMonitorEntry from './LogMonitorEntry';
|
import LogMonitorEntry from './LogMonitorEntry';
|
||||||
|
|
||||||
|
const ulStyle = {
|
||||||
|
listStyle: "none",
|
||||||
|
padding: "20px 0 20px",
|
||||||
|
position: "relative"
|
||||||
|
};
|
||||||
|
|
||||||
export default class LogMonitor {
|
export default class LogMonitor {
|
||||||
constructor() {
|
constructor() {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
|
@ -137,7 +143,9 @@ export default class LogMonitor {
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<ul style={ulStyle}>
|
||||||
{elements}
|
{elements}
|
||||||
|
</ul>
|
||||||
<div>
|
<div>
|
||||||
{computedStates.length > 1 &&
|
{computedStates.length > 1 &&
|
||||||
<a onClick={::this.handleRollback}
|
<a onClick={::this.handleRollback}
|
||||||
|
|
|
@ -1,4 +1,40 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes, Component } from 'react';
|
||||||
|
|
||||||
|
const preStyle = {
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
color: "white",
|
||||||
|
border: 0,
|
||||||
|
margin: 0,
|
||||||
|
padding: 0
|
||||||
|
};
|
||||||
|
const h4Style = {
|
||||||
|
fontWeight: 500,
|
||||||
|
lineHeight: 1.1,
|
||||||
|
fontSize: "18px",
|
||||||
|
marginTop: "10px",
|
||||||
|
marginBottom: "10px"
|
||||||
|
}
|
||||||
|
const liStyle = {
|
||||||
|
marginBottom: "20px",
|
||||||
|
position: "relative"
|
||||||
|
};
|
||||||
|
const wrap1Style = {
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
overflow: "auto"
|
||||||
|
};
|
||||||
|
const wrap2Style = {
|
||||||
|
display: "table",
|
||||||
|
tableLayout: "fixed",
|
||||||
|
width: "100%"
|
||||||
|
};
|
||||||
|
const wrap3Style = {
|
||||||
|
width: "100%",
|
||||||
|
display: "table-cell"
|
||||||
|
};
|
||||||
|
const wrap3StyleMax = {
|
||||||
|
width: "800px",
|
||||||
|
display: "table-cell"
|
||||||
|
};
|
||||||
|
|
||||||
function hsvToRgb(h, s, v) {
|
function hsvToRgb(h, s, v) {
|
||||||
const i = Math.floor(h);
|
const i = Math.floor(h);
|
||||||
|
@ -34,7 +70,15 @@ function colorFromString(token) {
|
||||||
return hsvToRgb(h, s, v);
|
return hsvToRgb(h, s, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class LogMonitorEntry {
|
export default class LogMonitorEntry extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
maximizedAction: false,
|
||||||
|
maximizedState: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
index: PropTypes.number.isRequired,
|
index: PropTypes.number.isRequired,
|
||||||
state: PropTypes.object.isRequired,
|
state: PropTypes.object.isRequired,
|
||||||
|
@ -49,7 +93,7 @@ export default class LogMonitorEntry {
|
||||||
let errorText = error;
|
let errorText = error;
|
||||||
if (!errorText) {
|
if (!errorText) {
|
||||||
try {
|
try {
|
||||||
return JSON.stringify(this.props.select(state));
|
return JSON.stringify(this.props.select(state), null, 2);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errorText = 'Error selecting state.';
|
errorText = 'Error selecting state.';
|
||||||
}
|
}
|
||||||
|
@ -64,7 +108,7 @@ export default class LogMonitorEntry {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleActionClick() {
|
handleCollapseClick() {
|
||||||
const { index, onActionClick } = this.props;
|
const { index, onActionClick } = this.props;
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
onActionClick(index);
|
onActionClick(index);
|
||||||
|
@ -73,49 +117,72 @@ export default class LogMonitorEntry {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { index, error, action, state, collapsed } = this.props;
|
const { index, error, action, state, collapsed } = this.props;
|
||||||
|
const { maximizedAction, maximizedState } = this.state;
|
||||||
|
if (!action.type) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
const { r, g, b } = colorFromString(action.type);
|
const { r, g, b } = colorFromString(action.type);
|
||||||
|
const colorStyle = {color: `rgb(${r}, ${g}, ${b})`};
|
||||||
|
|
||||||
|
|
||||||
|
// Heading
|
||||||
|
const actionComponent = !maximizedAction ? (
|
||||||
|
<h4 style={{...h4Style, color: `rgb(${r}, ${g}, ${b})`,}}>
|
||||||
|
{"+ " + action.type}
|
||||||
|
</h4>
|
||||||
|
) : (
|
||||||
|
<pre style={preStyle}>
|
||||||
|
<a style={colorStyle}>
|
||||||
|
{"- " + JSON.stringify(action, null, 2)}
|
||||||
|
</a>
|
||||||
|
</pre>
|
||||||
|
);
|
||||||
|
|
||||||
|
// Action
|
||||||
|
const stateComponent = !maximizedState ? (
|
||||||
|
<h4 style={{...h4Style, color: "white"}}>
|
||||||
|
{"+ State: object {...}"}
|
||||||
|
</h4>
|
||||||
|
) : (
|
||||||
|
<pre style={preStyle}>
|
||||||
|
{"- " + this.printState(state, error)}
|
||||||
|
</pre>
|
||||||
|
);
|
||||||
|
|
||||||
|
const collapsedComponent = !collapsed ? <span>✔ Enabled</span> : <span>✘ Disabled</span>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<li style={liStyle}>
|
||||||
textDecoration: collapsed ? 'line-through' : 'none'
|
<div style={wrap1Style}>
|
||||||
}}>
|
<div style={wrap2Style}>
|
||||||
<a onClick={::this.handleActionClick}
|
<div style={maximizedAction || maximizedState ? wrap3StyleMax : wrap3Style}>
|
||||||
style={{
|
<a onClick={::this.handleCollapseClick} href="javascript:;">
|
||||||
opacity: collapsed ? 0.5 : 1,
|
{collapsedComponent}
|
||||||
marginTop: '1em',
|
</a>
|
||||||
display: 'block',
|
<a onClick={()=>this.setState({maximizedAction: !maximizedAction})} href="javascript:;">
|
||||||
paddingBottom: '1em',
|
{actionComponent}
|
||||||
paddingTop: '1em',
|
</a>
|
||||||
color: `rgb(${r}, ${g}, ${b})`,
|
<a onClick={()=>this.setState({maximizedState: !maximizedState})} href="javascript:;">
|
||||||
cursor: (index > 0) ? 'pointer' : 'default',
|
{stateComponent}
|
||||||
WebkitUserSelect: 'none'
|
|
||||||
}}>
|
|
||||||
{JSON.stringify(action)}
|
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
{!collapsed &&
|
|
||||||
<p style={{
|
|
||||||
textAlign: 'center',
|
|
||||||
transform: 'rotate(180deg)'
|
|
||||||
}}>
|
|
||||||
⇧
|
|
||||||
</p>
|
|
||||||
}
|
|
||||||
|
|
||||||
{!collapsed &&
|
|
||||||
<div style={{
|
|
||||||
paddingBottom: '1em',
|
|
||||||
paddingTop: '1em',
|
|
||||||
color: 'lightyellow'
|
|
||||||
}}>
|
|
||||||
{this.printState(state, error)}
|
|
||||||
</div>
|
</div>
|
||||||
}
|
|
||||||
|
|
||||||
<hr style={{
|
|
||||||
marginBottom: '2em'
|
|
||||||
}} />
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function getTimestring(d) {
|
||||||
|
var x = document.getElementById("demo");
|
||||||
|
var h = addZero(d.getHours(), 2);
|
||||||
|
var m = addZero(d.getMinutes(), 2);
|
||||||
|
var s = addZero(d.getSeconds(), 2);
|
||||||
|
var ms = addZero(d.getMilliseconds(), 3);
|
||||||
|
return h + ":" + m + ":" + s + ":" + ms;
|
||||||
|
}
|
||||||
|
function addZero(x, n) {
|
||||||
|
if (x.toString().length < n) {
|
||||||
|
x = "0" + x;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user