diff --git a/README.md b/README.md index 5c06e5d..c29353a 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Name | Description `preserveScrollTop` | When `true`, records the current scroll top every second so it can be restored on refresh. This only has effect when used together with `persistState()` enhancer from Redux DevTools. By default, set to `true`. `expandActionRoot` | When `true`, displays the action object expanded rather than collapsed. By default, set to `false`. `expandStateRoot` | When `true`, displays the state object expanded rather than collapsed. By default, set to `false`. +`markStateDiff` | When `true`, mark the state's values which were changed comparing to the previous state. It affects the performance significantly! You might also want to set `expandStateRoot` to `true` as well when enabling it. By default, set to `false`. ### License diff --git a/src/LogMonitor.js b/src/LogMonitor.js index 8dce38f..ada7f17 100644 --- a/src/LogMonitor.js +++ b/src/LogMonitor.js @@ -60,7 +60,8 @@ export default class LogMonitor extends Component { PropTypes.string ]), expandActionRoot: PropTypes.bool, - expandStateRoot: PropTypes.bool + expandStateRoot: PropTypes.bool, + markStateDiff: PropTypes.bool }; static defaultProps = { @@ -68,7 +69,8 @@ export default class LogMonitor extends Component { theme: 'nicinabox', preserveScrollTop: true, expandActionRoot: false, - expandStateRoot: false + expandStateRoot: false, + markStateDiff: false }; shouldComponentUpdate = shouldPureComponentUpdate; @@ -186,8 +188,9 @@ export default class LogMonitor extends Component { computedStates, select, expandActionRoot, - expandStateRoot - } = this.props; + expandStateRoot, + markStateDiff + } = this.props; const entryListProps = { theme, @@ -198,6 +201,7 @@ export default class LogMonitor extends Component { select, expandActionRoot, expandStateRoot, + markStateDiff, onActionClick: this.handleToggleAction }; diff --git a/src/LogMonitorEntry.js b/src/LogMonitorEntry.js index 67938f4..72de267 100644 --- a/src/LogMonitorEntry.js +++ b/src/LogMonitorEntry.js @@ -51,30 +51,35 @@ export default class LogMonitorEntry extends Component { if (!errorText) { try { const data = this.props.select(state); - const previousData = typeof this.props.previousState !== 'undefined' ? - this.props.select(this.props.previousState) : - undefined; - const getValueStyle = ({ style }, nodeType, keyPath) => ({ - style: { - ...style, - ...(dataIsEqual(data, previousData, keyPath) ? {} : styles.changedData) - } - }); - const getNestedNodeStyle = ({ style }, keyPath) => ({ - style: { - ...style, - ...(keyPath.length > 1 ? {} : styles.root) - } - }); + let theme = this.props.theme; + + if (this.props.markStateDiff) { + const previousData = typeof this.props.previousState !== 'undefined' ? + this.props.select(this.props.previousState) : + undefined; + const getValueStyle = ({ style }, nodeType, keyPath) => ({ + style: { + ...style, + ...(dataIsEqual(data, previousData, keyPath) ? {} : styles.changedData) + } + }); + const getNestedNodeStyle = ({ style }, keyPath) => ({ + style: { + ...style, + ...(keyPath.length > 1 ? {} : styles.root) + } + }); + theme = { + extend: this.props.theme, + tree: styles.tree, + value: getValueStyle, + nestedNode: getNestedNodeStyle + }; + } return ( ); }