From 98cdc624d4125b8fbfb0004794c93852b56ec81f Mon Sep 17 00:00:00 2001 From: Ben Verbeken Date: Thu, 24 Jan 2019 09:26:42 +0100 Subject: [PATCH] code cleanup --- src/main/Embeddable.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/Embeddable.js b/src/main/Embeddable.js index 6d8b427..9c96ecd 100644 --- a/src/main/Embeddable.js +++ b/src/main/Embeddable.js @@ -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() { @@ -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); }); }