From ff15b2b88abe93739fefcdadfb5411869eeddd30 Mon Sep 17 00:00:00 2001 From: Peter Halliday Date: Sun, 8 Feb 2015 00:05:31 +0100 Subject: [PATCH] add chart.js to peer dependencies and require it in core --- lib/core.js | 51 +++++++++++++++++++++++++-------------------------- package.json | 3 ++- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/core.js b/lib/core.js index a49d68f..cd43294 100644 --- a/lib/core.js +++ b/lib/core.js @@ -23,36 +23,35 @@ module.exports = { }; } - if (global.Chart) { - classData.componentDidMount = function() { - this.initializeChart(this.props); - }; + classData.componentDidMount = function() { + this.initializeChart(this.props); + }; - classData.componentWillUnmount = function() { - var chart = this.state.chart; - chart.destroy(); - }; + classData.componentWillUnmount = function() { + var chart = this.state.chart; + chart.destroy(); + }; - classData.componentWillReceiveProps = function(nextProps) { - var chart = this.state.chart; - chart.destroy(); - this.initializeChart(nextProps); - }; + classData.componentWillReceiveProps = function(nextProps) { + var chart = this.state.chart; + chart.destroy(); + this.initializeChart(nextProps); + }; - classData.initializeChart = function(nextProps) { - var el = this.getDOMNode(); - var ctx = el.getContext("2d"); - var chart = new Chart(ctx)[chartType](nextProps.data, nextProps.options || {}); - this.state.chart = chart; - }; + classData.initializeChart = function(nextProps) { + var Chart = require('chart.js'); + var el = this.getDOMNode(); + var ctx = el.getContext("2d"); + var chart = new Chart(ctx)[chartType](nextProps.data, nextProps.options || {}); + this.state.chart = chart; + }; - var i; - for (i=0; i