-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
fba1596
commit 3a718de
Showing
1 changed file
with
14 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,6 +167,10 @@ export class Content extends Ion implements OnDestroy, OnInit { | |
_fixedEle: HTMLElement; | ||
/** @internal */ | ||
_imgs: Img[] = []; | ||
/** @internal */ | ||
_viewCtrlReadSub: any; | ||
/** @internal */ | ||
_viewCtrlWriteSub: any; | ||
|
||
private _imgReqBfr: number; | ||
private _imgRndBfr: number; | ||
|
@@ -328,33 +332,28 @@ export class Content extends Ion implements OnDestroy, OnInit { | |
this._imgReqBfr = config.getNumber('imgRequestBuffer', 1400); | ||
this._imgRndBfr = config.getNumber('imgRenderBuffer', 400); | ||
this._imgVelMax = config.getNumber('imgVelocityMax', 3); | ||
this._scroll = new ScrollView(_plt, _dom); | ||
|
||
if (viewCtrl) { | ||
// content has a view controller | ||
viewCtrl._setIONContent(this); | ||
viewCtrl._setIONContentRef(elementRef); | ||
|
||
var readSub = viewCtrl.readReady.subscribe(() => { | ||
readSub.unsubscribe(); | ||
this._viewCtrlReadSub = viewCtrl.readReady.subscribe(() => { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
manucorporat
Contributor
|
||
this._viewCtrlReadSub.unsubscribe(); | ||
this._readDimensions(); | ||
}); | ||
|
||
var writeSub = viewCtrl.writeReady.subscribe(() => { | ||
writeSub.unsubscribe(); | ||
this._viewCtrlWriteSub = viewCtrl.writeReady.subscribe(() => { | ||
this._viewCtrlWriteSub.unsubscribe(); | ||
this._writeDimensions(); | ||
}); | ||
|
||
} else { | ||
// content does not have a view controller | ||
_dom.read(() => { | ||
this._readDimensions(); | ||
}); | ||
_dom.write(() => { | ||
this._writeDimensions(); | ||
}); | ||
_dom.read(this._readDimensions.bind(this)); | ||
_dom.write(this._writeDimensions.bind(this)); | ||
} | ||
|
||
this._scroll = new ScrollView(_plt, _dom); | ||
} | ||
|
||
/** | ||
|
@@ -400,6 +399,9 @@ export class Content extends Ion implements OnDestroy, OnInit { | |
*/ | ||
ngOnDestroy() { | ||
this._scLsn && this._scLsn(); | ||
this._viewCtrlReadSub && this._viewCtrlReadSub.unsubscribe(); | ||
this._viewCtrlWriteSub && this._viewCtrlWriteSub.unsubscribe(); | ||
this._viewCtrlReadSub = this._viewCtrlWriteSub = null; | ||
this._scroll && this._scroll.destroy(); | ||
this._scrollEle = this._fixedEle = this._footerEle = this._scLsn = this._scroll = null; | ||
} | ||
|
Wouldn't it be cleaner if you did:
Instead of unsubscribing inside the subscribe handler?
Also for ngDestroy you can use takeUntil instead of unsubscribing as Ben Lesh suggests: