implement reactjs history

This commit is contained in:
Eric Hulburd
2016-03-04 13:59:34 -06:00
parent 5b218f6518
commit aa885f331c
27 changed files with 549 additions and 546 deletions

View File

@@ -8,27 +8,29 @@ class GraphComponent extends React.Component {
componentDidMount(){
var energy_graph = this;
if (energy_graph.house) energy_graph.updateGraph();
energy_graph.updateGraph();
}
get house(){
return this.props.location.state && this.props.location.state.house;
return this.props.house;
}
componentDidUpdate(prev_props, prev_state, prev_context){
var energy_graph = this;
if (energy_graph.shouldUpdateGraph(prev_props)) { energy_graph.updateGraph(); }
get state_manager(){
return this.props.state_manager;
}
shouldUpdateGraph(prev_props){
componentDidUpdate(prev_props, prev_state){
var energy_graph = this;
return energy_graph.house && !prev_props.location.state.house ||
prev_props.location.state.house.id != energy_graph.house.id;
if (prev_props.house != energy_graph.props.house ||
prev_props.year != energy_graph.props.year ||
prev_props.graph_attr != energy_graph.props.graph_attr){
energy_graph.updateGraph();
}
}
updateGraph(){
var energy_graph = this,
graph_attr = energy_graph.props.params.graph_attr;
graph_attr = energy_graph.props.graph_attr;
if (energy_graph.graph === undefined){
energy_graph.graph = new CalendarGridChart({
@@ -68,8 +70,4 @@ class GraphComponent extends React.Component {
}
GraphComponent.contextTypes = {
router: React.PropTypes.object.isRequired
};
export default GraphComponent;
module.exports = GraphComponent;