From 58fe613e89740598d0ee6a2a8303de1f5ba50bbf Mon Sep 17 00:00:00 2001 From: Dylan Munyard Date: Mon, 2 Oct 2017 01:36:32 +1000 Subject: [PATCH 1/2] migrate from React.createClass to JavaScript classes, https://reactjs.org/blog/2017/04/07/react-v15.5.0.html --- lib/core.js | 169 ++++++++++++++++++++++++++++------------------------ 1 file changed, 90 insertions(+), 79 deletions(-) diff --git a/lib/core.js b/lib/core.js index b39d67b..abbcbe6 100644 --- a/lib/core.js +++ b/lib/core.js @@ -2,91 +2,102 @@ var React = require('react'); var ReactDOM = require('react-dom'); module.exports = { - createClass: function(chartType, methodNames, dataKey) { - var excludedProps = ['data', 'options', 'redraw']; - var classData = { - displayName: chartType + 'Chart', - getInitialState: function() { return {}; }, - render: function() { - var _props = { - ref: 'canvass' - }; - for (var name in this.props) { - if (this.props.hasOwnProperty(name)) { - if (excludedProps.indexOf(name) === -1) { - _props[name] = this.props[name]; + createClass: function(chartType, methodNames, dataKey) { + var excludedProps = ['data', 'options', 'redraw']; + + class ChartComponent extends React.Component { + constructor(props) { + super(props); + this.displayName = chartType + 'Chart'; + this.chart = {}; + this.canvas = null; } - } - } - return React.createElement('canvas', _props); - } - }; - - var extras = ['clear', 'stop', 'resize', 'toBase64Image', 'generateLegend', 'update', 'addData', 'removeData']; - function extra(type) { - classData[type] = function() { - return this.state.chart[type].apply(this.state.chart, arguments); - }; - } - - classData.componentDidMount = function() { - this.initializeChart(this.props); - }; - classData.componentWillUnmount = function() { - var chart = this.state.chart; - chart.destroy(); - }; + componentDidMount() { + this.initializeChart(); + + this.canvas = ReactDOM.findDOMNode(this); + + var extras = ['clear', 'stop', 'resize', 'toBase64Image', 'generateLegend', 'update', 'addData', 'removeData'], + i; + for (i=0; i Date: Mon, 2 Oct 2017 01:48:41 +1000 Subject: [PATCH 2/2] Remove the use the of refs --- lib/core.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/core.js b/lib/core.js index abbcbe6..c0ec668 100644 --- a/lib/core.js +++ b/lib/core.js @@ -81,9 +81,7 @@ module.exports = { getCanvas() { return this.getCanvass() }; render() { - var _props = { - ref: 'canvass' - }; + var _props = {}; for (var name in this.props) { if (this.props.hasOwnProperty(name)) { if (excludedProps.indexOf(name) === -1) {