Skip to content

Commit

Permalink
fix(datepicker): Fixed destroyed view errors
Browse files Browse the repository at this point in the history
  • Loading branch information
edcarroll authored and mcosta74 committed Aug 14, 2017
1 parent 2562cb8 commit e38caf5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
16 changes: 5 additions & 11 deletions src/modules/popup/classes/popup-component-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SuiComponentFactory } from "../../../misc/util/index";
import { SuiPopupController } from "./popup-controller";
import { PopupConfig } from "./popup-config";

export class SuiPopupComponentController<T> extends SuiPopupController implements OnDestroy {
export class SuiPopupComponentController<T> extends SuiPopupController {
// Stores reference to generated content component.
private _contentComponentRef?:ComponentRef<T>;

Expand All @@ -20,13 +20,6 @@ export class SuiPopupComponentController<T> extends SuiPopupController implement
config:PopupConfig) {

super(renderer, element, componentFactory, config);

this.popup.onClose.subscribe(() => {
if (this._contentComponentRef) {
this._contentComponentRef.destroy();
this._contentComponentRef = undefined;
}
});
}

public open():void {
Expand All @@ -38,11 +31,12 @@ export class SuiPopupComponentController<T> extends SuiPopupController implement
super.open();
}

public ngOnDestroy():void {
protected cleanup():void {
super.cleanup();

if (this._contentComponentRef) {
this._contentComponentRef.destroy();
this._contentComponentRef = undefined;
}

super.ngOnDestroy();
}
}
25 changes: 16 additions & 9 deletions src/modules/popup/classes/popup-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ export abstract class SuiPopupController implements IPopup, OnDestroy {
this.popup.config = config;

// When the popup is closed (onClose fires on animation complete),
this.popup.onClose.subscribe(() => {
this._componentRef.instance.positioningService.destroy();
this._componentFactory.detachFromApplication(this._componentRef);

// Remove the document click handler
this._documentListener();
});
this.popup.onClose.subscribe(() => this.cleanup());
}

public configure(config?:IPopupConfig):void {
Expand Down Expand Up @@ -175,9 +169,22 @@ export abstract class SuiPopupController implements IPopup, OnDestroy {
}
}

public ngOnDestroy():void {
protected cleanup():void {
clearTimeout(this._openingTimeout);

if (this._componentRef.instance && this._componentRef.instance.positioningService) {
this._componentRef.instance.positioningService.destroy();
}

this._componentFactory.detachFromApplication(this._componentRef);
this._componentRef.destroy();

if (this._documentListener) {
// Remove the document click handler
this._documentListener();
}
}

public ngOnDestroy():void {
this.cleanup();
}
}
8 changes: 4 additions & 4 deletions src/modules/popup/components/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class SuiPopup implements IPopup {
// Keeps track of whether the popup is open internally.
private _isOpen:boolean;
// `setTimeout` timer pointer for cancelling popup close.
private _closingTimeout:number;
public closingTimeout:number;

// Fires when the popup opens (and the animation is completed).
public onOpen:EventEmitter<void>;
Expand Down Expand Up @@ -140,7 +140,7 @@ export class SuiPopup implements IPopup {
// Only attempt to open if currently closed.
if (!this.isOpen) {
// Cancel the closing timer.
clearTimeout(this._closingTimeout);
clearTimeout(this.closingTimeout);

// Cancel all other transitions, and initiate the opening transition.
this.transitionController.stopAll();
Expand Down Expand Up @@ -183,9 +183,9 @@ export class SuiPopup implements IPopup {
new Transition(this.config.transition, this.config.transitionDuration, TransitionDirection.Out));

// Cancel the closing timer.
clearTimeout(this._closingTimeout);
clearTimeout(this.closingTimeout);
// Start the closing timer, that fires the `onClose` event after the transition duration number of milliseconds.
this._closingTimeout = window.setTimeout(() => this.onClose.emit(), this.config.transitionDuration);
this.closingTimeout = window.setTimeout(() => this.onClose.emit(), this.config.transitionDuration);

// Finally, set the popup to be closed.
this._isOpen = false;
Expand Down

0 comments on commit e38caf5

Please sign in to comment.