-
Notifications
You must be signed in to change notification settings - Fork 6.8k
unsubscribe
some subscriptions on destroy / first
some subscriptions
#1549
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { | |
QueryList | ||
} from '@angular/core'; | ||
|
||
import { Subscription } from 'rxjs/Subscription'; | ||
/** | ||
* Shared directive to count lines inside a text area, such as a list item. | ||
* Line elements can be extracted with a @ContentChildren(MdLine) query, then | ||
|
@@ -16,15 +17,20 @@ export class MdLine {} | |
|
||
/* Helper that takes a query list of lines and sets the correct class on the host */ | ||
export class MdLineSetter { | ||
private _changesSubscription: Subscription; | ||
|
||
constructor(private _lines: QueryList<MdLine>, private _renderer: Renderer, | ||
private _element: ElementRef) { | ||
this._setLineClass(this._lines.length); | ||
|
||
this._lines.changes.subscribe(() => { | ||
this._changesSubscription = this._lines.changes.subscribe(() => { | ||
this._setLineClass(this._lines.length); | ||
}); | ||
} | ||
|
||
public destroy() { | ||
this._changesSubscription.unsubscribe(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This particular unsubscription isn't necessary because the |
||
|
||
private _setLineClass(count: number): void { | ||
this._resetClasses(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { | |
NgModule, | ||
ModuleWithProviders, | ||
AfterContentInit, | ||
OnDestroy, | ||
Component, | ||
ContentChildren, | ||
ElementRef, | ||
|
@@ -17,6 +18,7 @@ import { | |
} from '@angular/core'; | ||
import {CommonModule} from '@angular/common'; | ||
import {Dir, MdError} from '../core'; | ||
import {Subscription} from 'rxjs/Subscription'; | ||
|
||
/** Exception thrown when two MdSidenav are matching the same side. */ | ||
export class MdDuplicatedSidenavError extends MdError { | ||
|
@@ -66,7 +68,6 @@ export class MdSidenav { | |
/** Event emitted when the sidenav is fully closed. */ | ||
@Output('close') onClose = new EventEmitter<void>(); | ||
|
||
|
||
/** | ||
* @param _elementRef The DOM element reference. Used for transition and width calculation. | ||
* If not available we do not hook on transitions. | ||
|
@@ -240,12 +241,14 @@ export class MdSidenav { | |
], | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class MdSidenavLayout implements AfterContentInit { | ||
export class MdSidenavLayout implements AfterContentInit, OnDestroy { | ||
@ContentChildren(MdSidenav) _sidenavs: QueryList<MdSidenav>; | ||
|
||
get start() { return this._start; } | ||
get end() { return this._end; } | ||
|
||
private _sidenavChangesSubscription: Subscription; | ||
|
||
/** The sidenav at the start/end alignment, independent of direction. */ | ||
private _start: MdSidenav; | ||
private _end: MdSidenav; | ||
|
@@ -271,11 +274,16 @@ export class MdSidenavLayout implements AfterContentInit { | |
/** TODO: internal */ | ||
ngAfterContentInit() { | ||
// On changes, assert on consistency. | ||
this._sidenavs.changes.subscribe(() => this._validateDrawers()); | ||
this._sidenavChangesSubscription = this._sidenavs.changes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one also shouldn't be necessary because the |
||
.subscribe(() => this._validateDrawers()); | ||
this._sidenavs.forEach((sidenav: MdSidenav) => this._watchSidenavToggle(sidenav)); | ||
this._validateDrawers(); | ||
} | ||
|
||
ngOnDestroy() { | ||
this._sidenavChangesSubscription.unsubscribe(); | ||
} | ||
|
||
/* | ||
* Subscribes to sidenav events in order to set a class on the main layout element when the sidenav | ||
* is open and the backdrop is visible. This ensures any overflow on the layout element is properly | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove spaces from around imported symbol