Skip to content

Commit

Permalink
feat(changeDetection): detach Tabs when not active
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Apr 17, 2016
1 parent 79dd0df commit 0c4171e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ionic/components/tabs/tab.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Directive, Host, Inject, forwardRef, ElementRef, Compiler, AppViewManager, NgZone, Renderer, Type, ViewEncapsulation} from 'angular2/core';
import {Component, Directive, Host, Inject, forwardRef, ElementRef, Compiler, AppViewManager, NgZone, Renderer, Type, ViewEncapsulation, ChangeDetectorRef} from 'angular2/core';
import {EventEmitter, Input, Output} from 'angular2/core';

import {IonicApp} from '../app/app';
Expand Down Expand Up @@ -216,7 +216,8 @@ export class Tab extends NavController {
compiler: Compiler,
viewManager: AppViewManager,
zone: NgZone,
renderer: Renderer
renderer: Renderer,
private _cd: ChangeDetectorRef
) {
// A Tab is a NavController for its child pages
super(parentTabs, app, config, keyboard, elementRef, 'contents', compiler, viewManager, zone, renderer);
Expand Down Expand Up @@ -296,6 +297,16 @@ export class Tab extends NavController {
*/
setSelected(isSelected: boolean) {
this.isSelected = isSelected;

if (isSelected) {
// this is the selected tab, detect changes
this._cd.reattach();

} else {
// this tab is not selected, do not detect changes
this._cd.detach();
}

this.hideNavbars(!isSelected);
}

Expand Down

2 comments on commit 0c4171e

@manucorporat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamdbradley <ion-nav> also keeps the hidden pages in the DOM.
does it make sense to also detach/reattach from the changeDetector to save CPU cycles?

@manucorporat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok! that was done in: b282e90

right?

Please sign in to comment.