Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bverbeken committed Jan 24, 2019
1 parent 493e245 commit 98cdc62
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/main/Embeddable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ import React from 'react';
export default class Embeddable extends React.Component {

async componentDidMount() {
let seatsio = await this.getSeatsio();
let {id, className, onRenderStarted, chartJsUrl, ...config} = this.props;
const seatsio = await this.getSeatsio();
const config = this.extractConfigFromProps();
config.divId = this.props.id;
this.chartJsUrl = chartJsUrl;
let chart = this.createChart(seatsio, config).render();
const chart = this.createChart(seatsio, config).render();
this.chart = chart;
if (this.props.onRenderStarted) this.props.onRenderStarted(chart);
if (this.props.onRenderStarted) {
this.props.onRenderStarted(chart);
}
}

extractConfigFromProps() {
// noinspection JSUnusedLocalSymbols
let {id, className, onRenderStarted, chartJsUrl, ...config} = this.props;
return config;
}

componentWillUnmount() {
Expand All @@ -32,7 +39,7 @@ export default class Embeddable extends React.Component {
let script = document.createElement('script');
script.onload = () => resolve(seatsio);
script.onerror = () => reject(`Could not load ${script.src}`);
script.src = this.chartJsUrl;
script.src = this.props.chartJsUrl;
document.head.appendChild(script);
});
}
Expand Down

0 comments on commit 98cdc62

Please sign in to comment.