Skip to content

Commit 3a718de

Browse files
cmorbitzermanucorporat
authored andcommitted
fix(content): unsubscribe from viewCtrl observables after content ins… (#10050)
* fix(content): unsubscribe from observables on destroy * fix(content): scroll is initialized before subscribing fixes #9593 fixes #10045 * fix(content): unset viewCtrl subscribers on destroy
1 parent fba1596 commit 3a718de

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/components/content/content.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ export class Content extends Ion implements OnDestroy, OnInit {
167167
_fixedEle: HTMLElement;
168168
/** @internal */
169169
_imgs: Img[] = [];
170+
/** @internal */
171+
_viewCtrlReadSub: any;
172+
/** @internal */
173+
_viewCtrlWriteSub: any;
170174

171175
private _imgReqBfr: number;
172176
private _imgRndBfr: number;
@@ -328,33 +332,28 @@ export class Content extends Ion implements OnDestroy, OnInit {
328332
this._imgReqBfr = config.getNumber('imgRequestBuffer', 1400);
329333
this._imgRndBfr = config.getNumber('imgRenderBuffer', 400);
330334
this._imgVelMax = config.getNumber('imgVelocityMax', 3);
335+
this._scroll = new ScrollView(_plt, _dom);
331336

332337
if (viewCtrl) {
333338
// content has a view controller
334339
viewCtrl._setIONContent(this);
335340
viewCtrl._setIONContentRef(elementRef);
336341

337-
var readSub = viewCtrl.readReady.subscribe(() => {
338-
readSub.unsubscribe();
342+
this._viewCtrlReadSub = viewCtrl.readReady.subscribe(() => {
343+
this._viewCtrlReadSub.unsubscribe();
339344
this._readDimensions();
340345
});
341346

342-
var writeSub = viewCtrl.writeReady.subscribe(() => {
343-
writeSub.unsubscribe();
347+
this._viewCtrlWriteSub = viewCtrl.writeReady.subscribe(() => {
348+
this._viewCtrlWriteSub.unsubscribe();
344349
this._writeDimensions();
345350
});
346351

347352
} else {
348353
// content does not have a view controller
349-
_dom.read(() => {
350-
this._readDimensions();
351-
});
352-
_dom.write(() => {
353-
this._writeDimensions();
354-
});
354+
_dom.read(this._readDimensions.bind(this));
355+
_dom.write(this._writeDimensions.bind(this));
355356
}
356-
357-
this._scroll = new ScrollView(_plt, _dom);
358357
}
359358

360359
/**
@@ -400,6 +399,9 @@ export class Content extends Ion implements OnDestroy, OnInit {
400399
*/
401400
ngOnDestroy() {
402401
this._scLsn && this._scLsn();
402+
this._viewCtrlReadSub && this._viewCtrlReadSub.unsubscribe();
403+
this._viewCtrlWriteSub && this._viewCtrlWriteSub.unsubscribe();
404+
this._viewCtrlReadSub = this._viewCtrlWriteSub = null;
403405
this._scroll && this._scroll.destroy();
404406
this._scrollEle = this._fixedEle = this._footerEle = this._scLsn = this._scroll = null;
405407
}

0 commit comments

Comments
 (0)