Skip to content

Commit 8b204fe

Browse files
author
Sumo
committed
add fcevent- attribute in component to addeventlistener callback in parent
1 parent cc65cd2 commit 8b204fe

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/ReactFC.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
3636

3737
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
3838

39+
var staticEvents = ['ready', 'beforeinitialize', 'initialized'];
40+
3941
var ReactFC = function (_React$Component) {
4042
_inherits(ReactFC, _React$Component);
4143

@@ -257,10 +259,25 @@ var ReactFC = function (_React$Component) {
257259
}, {
258260
key: 'renderChart',
259261
value: function renderChart() {
262+
var _this4 = this;
263+
260264
var currentOptions = this.resolveChartOptions(this.props);
261265
currentOptions.renderAt = this.containerId;
262266

263267
this.chartObj = new this.FusionCharts(currentOptions);
268+
Object.keys(this.props).forEach(function (value) {
269+
var event = value.match(/^fcEvent-.*/i);
270+
271+
if (event && typeof _this4.props[value] === 'function') {
272+
var eventName = value.replace(/^fcEvent-/i, '');
273+
274+
if (staticEvents.indexOf(eventName.toLowerCase()) > -1) {
275+
_this4.FusionCharts.addEventListener(eventName, _this4.props[value]);
276+
} else {
277+
_this4.chartObj.addEventListener(eventName, _this4.props[value]);
278+
}
279+
}
280+
});
264281
this.chartObj.render();
265282
this.oldOptions = currentOptions;
266283
}

src/ReactFC.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import uuid from 'uuid/v4';
44
import * as utils from './utils/utils';
55
import fusionChartsOptions from './utils/options';
66

7+
const staticEvents = ['ready', 'beforeinitialize', 'initialized'];
8+
79
class ReactFC extends React.Component {
810
static fcRoot(core, ...modules) {
911
modules.forEach((m) => {
@@ -205,6 +207,19 @@ class ReactFC extends React.Component {
205207
currentOptions.renderAt = this.containerId;
206208

207209
this.chartObj = new this.FusionCharts(currentOptions);
210+
Object.keys(this.props).forEach((value) => {
211+
const event = value.match(/^fcEvent-.*/i);
212+
213+
if (event && typeof this.props[value] === 'function') {
214+
const eventName = value.replace(/^fcEvent-/i, '');
215+
216+
if (staticEvents.indexOf(eventName.toLowerCase()) > -1) {
217+
this.FusionCharts.addEventListener(eventName, this.props[value]);
218+
} else {
219+
this.chartObj.addEventListener(eventName, this.props[value]);
220+
}
221+
}
222+
});
208223
this.chartObj.render();
209224
this.oldOptions = currentOptions;
210225
}

0 commit comments

Comments
 (0)