Skip to content

Commit 1005084

Browse files
feat: [UEPR-268] clear resize observer
1 parent a699142 commit 1005084

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

core/inject.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ Blockly.init_ = function(mainWorkspace, container) {
368368
});
369369

370370
resizeObserver.observe(container);
371+
mainWorkspace.setResizeObserver(resizeObserver);
371372

372373
Blockly.inject.bindDocumentEvents_();
373374

core/workspace_svg.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,10 @@ Blockly.WorkspaceSvg = function(options, opt_blockDragSurface, opt_wsDragSurface
119119
goog.inherits(Blockly.WorkspaceSvg, Blockly.Workspace);
120120

121121
/**
122-
* A wrapper function called when a resize event occurs.
123-
* You can pass the result to `unbindEvent_`.
124-
* @type {Array.<!Array>}
122+
* Save resize observer of the canvas in order to unobserve later in dispose
123+
* @type {ResizeObserver}
125124
*/
126-
Blockly.WorkspaceSvg.prototype.resizeHandlerWrapper_ = null;
125+
Blockly.WorkspaceSvg.prototype.resizeObserver_ = null;
127126

128127
/**
129128
* The render status of an SVG workspace.
@@ -408,11 +407,11 @@ Blockly.WorkspaceSvg.prototype.getInjectionDiv = function() {
408407
};
409408

410409
/**
411-
* Save resize handler data so we can delete it later in dispose.
412-
* @param {!Array.<!Array>} handler Data that can be passed to unbindEvent_.
410+
* Save resize observer so we can delete it later in dispose.
411+
* @param {ResizeObserver} observer Data to unobserve.
413412
*/
414-
Blockly.WorkspaceSvg.prototype.setResizeHandlerWrapper = function(handler) {
415-
this.resizeHandlerWrapper_ = handler;
413+
Blockly.WorkspaceSvg.prototype.setResizeObserver = function(observer) {
414+
this.resizeObserver_ = observer;
416415
};
417416

418417
/**
@@ -547,9 +546,10 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
547546
// SVG is injected into (i.e. injectionDiv).
548547
goog.dom.removeNode(this.getParentSvg().parentNode);
549548
}
550-
if (this.resizeHandlerWrapper_) {
551-
Blockly.unbindEvent_(this.resizeHandlerWrapper_);
552-
this.resizeHandlerWrapper_ = null;
549+
550+
if (this.resizeObserver_) {
551+
this.resizeObserver_.disconnect();
552+
this.resizeObserver_ = null;
553553
}
554554
};
555555

0 commit comments

Comments
 (0)