Skip to content

Commit

Permalink
Implement markStateDiff property to assure rendering optimizations in…
Browse files Browse the repository at this point in the history
…side JSONTree
  • Loading branch information
zalmoxisus committed Oct 19, 2016
1 parent 6413dfb commit 4eb3e71
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 8 additions & 4 deletions src/LogMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ export default class LogMonitor extends Component {
PropTypes.string
]),
expandActionRoot: PropTypes.bool,
expandStateRoot: PropTypes.bool
expandStateRoot: PropTypes.bool,
markStateDiff: PropTypes.bool
};

static defaultProps = {
select: (state) => state,
theme: 'nicinabox',
preserveScrollTop: true,
expandActionRoot: false,
expandStateRoot: false
expandStateRoot: false,
markStateDiff: false
};

shouldComponentUpdate = shouldPureComponentUpdate;
Expand Down Expand Up @@ -186,8 +188,9 @@ export default class LogMonitor extends Component {
computedStates,
select,
expandActionRoot,
expandStateRoot
} = this.props;
expandStateRoot,
markStateDiff
} = this.props;

const entryListProps = {
theme,
Expand All @@ -198,6 +201,7 @@ export default class LogMonitor extends Component {
select,
expandActionRoot,
expandStateRoot,
markStateDiff,
onActionClick: this.handleToggleAction
};

Expand Down
47 changes: 26 additions & 21 deletions src/LogMonitorEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<JSONTree
theme={{
extend: this.props.theme,
tree: styles.tree,
value: getValueStyle,
nestedNode: getNestedNodeStyle
}}
theme={theme}
data={data}
invertTheme={false}
keyPath={['state']}
Expand Down
2 changes: 2 additions & 0 deletions src/LogMonitorEntryList.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class LogMonitorEntryList extends Component {
stagedActionIds,
expandActionRoot,
expandStateRoot,
markStateDiff,
onActionClick
} = this.props;

Expand All @@ -55,6 +56,7 @@ export default class LogMonitorEntryList extends Component {
error={error}
expandActionRoot={expandActionRoot}
expandStateRoot={expandStateRoot}
markStateDiff={markStateDiff}
onActionClick={onActionClick} />
);
}
Expand Down

0 comments on commit 4eb3e71

Please sign in to comment.