Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(content): use observables instead of unsubscribe #10098

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/components/content/content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, NgZone, OnDestroy, OnInit, Optional, Output, Renderer, ViewEncapsulation } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/takeUntil';

import { App } from '../app/app';
import { Config } from '../../config/config';
Expand Down Expand Up @@ -168,9 +171,7 @@ export class Content extends Ion implements OnDestroy, OnInit {
/** @internal */
_imgs: Img[] = [];
/** @internal */
_viewCtrlReadSub: any;
/** @internal */
_viewCtrlWriteSub: any;
_componentDestroyed: Subject<any> = new Subject();

private _imgReqBfr: number;
private _imgRndBfr: number;
Expand Down Expand Up @@ -339,15 +340,19 @@ export class Content extends Ion implements OnDestroy, OnInit {
viewCtrl._setIONContent(this);
viewCtrl._setIONContentRef(elementRef);

this._viewCtrlReadSub = viewCtrl.readReady.subscribe(() => {
this._viewCtrlReadSub.unsubscribe();
this._readDimensions();
});
viewCtrl.readReady
.takeUntil(this._componentDestroyed)
.take(1)
.subscribe(() => {
this._readDimensions();
});

this._viewCtrlWriteSub = viewCtrl.writeReady.subscribe(() => {
this._viewCtrlWriteSub.unsubscribe();
this._writeDimensions();
});
viewCtrl.writeReady
.takeUntil(this._componentDestroyed)
.take(1)
.subscribe(() => {
this._writeDimensions();
});

} else {
// content does not have a view controller
Expand Down Expand Up @@ -398,10 +403,9 @@ export class Content extends Ion implements OnDestroy, OnInit {
* @private
*/
ngOnDestroy() {
this._componentDestroyed.next(true);
this._componentDestroyed = null;
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;
}
Expand Down