Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
fix destroy method in media query service to use unsubscribe (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackbaud-PatrickOFriel authored Feb 3, 2017
1 parent befd7f8 commit 4d72567
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/modules/testing/mocks/mock-media-query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export class MockSkyMediaQueryService extends SkyMediaQueryService {
this._currentBreakpoints = breakpoints;
}

private _currentBreakpoints: SkyMediaBreakpoints = SkyMediaBreakpoints.md;

private currentMockSubject: BehaviorSubject<SkyMediaBreakpoints>
public currentMockSubject: BehaviorSubject<SkyMediaBreakpoints>
= new BehaviorSubject<SkyMediaBreakpoints>(this.current);

private _currentBreakpoints: SkyMediaBreakpoints = SkyMediaBreakpoints.md;

constructor() {
super(new NgZone({enableLongStackTrace: true}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,9 @@ describe('Tile dashboard service', () => {
it(
'should release resources when destroyed',
inject([SkyTileDashboardService], (dashboardService: SkyTileDashboardService) => {
let destroySpy = spyOn(mockMediaQueryService, 'destroy');

dashboardService.destroy();

expect(destroySpy).toHaveBeenCalled();
expect(mockMediaQueryService.currentMockSubject.observers.length).toBe(0);
})
);
});
10 changes: 7 additions & 3 deletions src/modules/tiles/tile-dashboard/tile-dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from '@angular/core';
import { DragulaService } from 'ng2-dragula/ng2-dragula';

import { Subscription } from 'rxjs';

import {
SkyMediaBreakpoints,
SkyMediaQueryService
Expand Down Expand Up @@ -58,6 +60,8 @@ export class SkyTileDashboardService {

private singleColumn: SkyTileDashboardColumnComponent;

private mediaSubscription: Subscription;

constructor(
private dragulaService: DragulaService,
private mediaQuery: SkyMediaQueryService
Expand Down Expand Up @@ -146,8 +150,8 @@ export class SkyTileDashboardService {

public destroy() {
/*istanbul ignore else */
if (this.mediaQuery) {
this.mediaQuery.destroy();
if (this.mediaSubscription) {
this.mediaSubscription.unsubscribe();
}
}

Expand Down Expand Up @@ -322,7 +326,7 @@ export class SkyTileDashboardService {
}

private initMediaQueries() {
this.mediaQuery.subscribe(
this.mediaSubscription = this.mediaQuery.subscribe(
(args: SkyMediaBreakpoints) => {
this.changeColumnMode(args === SkyMediaBreakpoints.xs || args === SkyMediaBreakpoints.sm);
}
Expand Down

0 comments on commit 4d72567

Please sign in to comment.