Skip to content

Commit 56a819b

Browse files
committed
Fix dataStore location + Firefox Bug is no longer present
1 parent 6d1001b commit 56a819b

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

vaadin-chartjs-wrapper/src/main/resources/META-INF/resources/frontend/src/chartControlFunc.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ if(window.xVaadinChartjsWrapper == undefined) window.xVaadinChartjsWrapper = {};
33
/** https://stackoverflow.com/a/46522991 */
44
if(!window.xVaadinChartjsWrapper.dataStorage) {
55
window.xVaadinChartjsWrapper.dataStorage = {
6-
_storage: new WeakMap(),
6+
_storage: new WeakMap(), /* This is important to not cause a memory leak */
77
put: function (element, key, obj) {
88
if (!this._storage.has(element)) {
99
this._storage.set(element, new Map());
@@ -35,36 +35,32 @@ window.xVaadinChartjsWrapper.buildChart = function buildChart(parentId, canvasId
3535
console.log("buildChart: parent was null!");
3636
return;
3737
}
38-
38+
3939
while (parent.firstChild) {
4040
parent.removeChild(parent.firstChild);
4141
}
42-
42+
4343
let canvas = document.createElement("canvas");
4444
canvas.id = canvasId;
4545

4646
parent.appendChild(canvas);
4747

4848
let ctx = canvas.getContext('2d');
4949

50-
// Run async due to https://bugzilla.mozilla.org/show_bug.cgi?id=1792860
51-
setTimeout(() => {
52-
let chart = new Chart(ctx, jsonpayload);
50+
let chart = new Chart(ctx, jsonpayload);
5351

54-
// Add chart to canvas
55-
dataStorage.put(document.getElementById(canvasId), 'chart-data', chart);
56-
}, 1);
52+
// Add chart to canvas
53+
window.xVaadinChartjsWrapper.dataStorage.put(document.getElementById(canvasId), 'chart-data', chart);
5754
}
5855

5956
window.xVaadinChartjsWrapper.tryDestroyChart = function tryDestroyChart(canvasId) {
6057
let canvas = document.getElementById(canvasId);
61-
6258
if(canvas == null) {
6359
console.debug(`tryDestroyChart: Canvas[id=${canvasId}] was null!`);
6460
return;
6561
}
6662

67-
let chart = dataStorage.get(canvas, 'chart-data');
63+
let chart = window.xVaadinChartjsWrapper.dataStorage.get(canvas, 'chart-data');
6864

6965
if(chart == null) {
7066
console.debug(`tryDestroyChart: Chart in Canvas[id=${canvasId}] was null!`);

0 commit comments

Comments
 (0)