Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

added immutable-js support via toMutable function #4

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Redux DevTools Chart Monitor
=========================

A chart monitor for [Redux DevTools](https://github.com/gaearon/redux-devtools).
A chart monitor for [Redux DevTools](https://github.com/gaearon/redux-devtools).
It shows a real-time view of the store aka the current state of the app.

:rocket: Now with immutable-js support.

[Demo](http://romseguy.github.io/redux-store-visualizer/) [(Source)](https://github.com/romseguy/redux-store-visualizer)

![Chart Monitor](https://camo.githubusercontent.com/19aebaeba929e97f97225115c49dc994299cb76e/687474703a2f2f692e696d6775722e636f6d2f4d53677655366c2e676966)
Expand Down Expand Up @@ -32,7 +34,7 @@ export default createDevTools(

Then you can render `<DevTools>` to any place inside app or even into a separate popup window.

Alternative, you can use it together with [`DockMonitor`](https://github.com/gaearon/redux-devtools-dock-monitor) to make it dockable.
Alternative, you can use it together with [`DockMonitor`](https://github.com/gaearon/redux-devtools-dock-monitor) to make it dockable.
Consult the [`DockMonitor` README](https://github.com/gaearon/redux-devtools-dock-monitor) for details of this approach.

[Read how to start using Redux DevTools.](https://github.com/gaearon/redux-devtools)
Expand Down Expand Up @@ -102,7 +104,9 @@ Consult the [`DockMonitor` README](https://github.com/gaearon/redux-devtools-doc
Name | Description
------------- | -------------
`theme` | Either a string referring to one of the themes provided by [redux-devtools-themes](https://github.com/gaearon/redux-devtools-themes) (feel free to contribute!) or a custom object of the same format. Optional. By default, set to [`'nicinabox'`](https://github.com/gaearon/redux-devtools-themes/blob/master/src/nicinabox.js).
`invertTheme` | Boolean value that will invert the colors of the selected theme. Optional. By default, set to `false`
`select` | A function that selects the slice of the state for DevTools to show. For example, `state => state.thePart.iCare.about`. Optional. By default, set to `state => state`.
`hasImmutables` | Boolean value that will walk state tree and convert immutable-js objects to normal objects so that they can be displayed. Optional. By default, set to `false`

### License

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"chart"
],
"author": "romseguy",
"contributors": [
"Cole Chamberlain <cole.chamberlain@gmail.com> (https://github.com/cchamberlain)"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/romseguy/redux-devtools-chart-monitor/issues"
Expand Down Expand Up @@ -49,6 +52,7 @@
"d3-state-visualizer": "^1.0.2",
"deepmerge": "^0.2.10",
"react-pure-render": "^1.0.2",
"redux-devtools-themes": "^1.0.0"
"redux-devtools-themes": "^1.0.0",
"tomutable": "^0.1.3"
}
}
4 changes: 0 additions & 4 deletions src/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ class Chart extends Component {
})
};

constructor(props) {
super(props);
}

componentDidMount() {
const { select, state } = this.props;
this.renderChart = tree(findDOMNode(this), this.props);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor extraneous here.

Expand Down
36 changes: 28 additions & 8 deletions src/ChartMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import shouldPureComponentUpdate from 'react-pure-render/function';
import * as themes from 'redux-devtools-themes';
import { ActionCreators } from 'redux-devtools';
import deepmerge from 'deepmerge';
import toMutable from 'tomutable';

import reducer from './reducers';
import Chart from './Chart';
Expand All @@ -19,6 +20,20 @@ const styles = {
}
};

function invertColors(theme) {
return {
...theme,
base00: theme.base07,
base01: theme.base06,
base02: theme.base05,
base03: theme.base04,
base04: theme.base03,
base05: theme.base02,
base06: theme.base01,
base07: theme.base00
};
}

class ChartMonitor extends Component {
static update = reducer;

Expand All @@ -37,13 +52,17 @@ class ChartMonitor extends Component {
theme: PropTypes.oneOfType([
PropTypes.object,
PropTypes.string
])
]),
invertTheme: PropTypes.bool,
hasImmutables: PropTypes.bool
};

static defaultProps = {
select: (state) => state,
theme: 'nicinabox',
preserveScrollTop: true
preserveScrollTop: true,
invertTheme: false,
hasImmutables: false
};

shouldComponentUpdate = shouldPureComponentUpdate;
Expand Down Expand Up @@ -78,17 +97,17 @@ class ChartMonitor extends Component {
}

getTheme() {
let { theme } = this.props;
let { theme, invertTheme } = this.props;
if (typeof theme !== 'string') {
return theme;
return invertTheme ? invertColors(theme) : theme;
}

if (typeof themes[theme] !== 'undefined') {
return themes[theme];
return invertTheme ? invertColors(themes[theme]) : themes[theme];
}

console.warn('DevTools theme ' + theme + ' not found, defaulting to nicinabox');
return themes.nicinabox;
return invertTheme ? invertColors(themes.nicinabox) : themes.nicinabox;
}

getChartStyle() {
Expand All @@ -115,7 +134,7 @@ class ChartMonitor extends Component {
}

getChartOptions(props = this.props) {
const { computedStates } = props;
const { computedStates, hasImmutables } = props;

const tooltipOptions = {
disabled: false,
Expand All @@ -129,8 +148,9 @@ class ChartMonitor extends Component {
}
};

let defaultState = computedStates[computedStates.length - 1].state;
const defaultOptions = {
state: computedStates[computedStates.length - 1].state,
state: hasImmutables ? toMutable(defaultState) : defaultState,
isSorted: false,
heightBetweenNodesCoeff: 1,
widthBetweenNodesCoeff: 1.3,
Expand Down