Skip to content

Commit

Permalink
feat(module:tooltip,popconfirm,popover): support OnPush
Browse files Browse the repository at this point in the history
add subject to support changeDetection of OnPush
change showcases’ changeDetection to OnPush

feat(module:popover): support OnPush

change binding name
change showcases’ changeDetection to OnPush
  • Loading branch information
csyszf committed Aug 28, 2017
1 parent 143c080 commit db60e48
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/components/popconfirm/nz-popconfirm.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { NzPopconfirmDirective } from './nz-popconfirm.directive';
import { FadeAnimation } from '../core/animation/fade-animations';
import { NzToolTipComponent } from '../tooltip/nz-tooltip.component';

@Component({
selector : 'nz-popconfirm',
encapsulation: ViewEncapsulation.None,
Expand All @@ -25,8 +26,8 @@ import { NzToolTipComponent } from '../tooltip/nz-tooltip.component';
(detach)="hide()"
(positionChange)="onPositionChange($event)"
[positions]="_positions"
[open]="nzVisible">
<div class="ant-popover" [ngClass]="_classMap" [ngStyle]="nzOverlayStyle" [@fadeAnimation]="''+nzVisible"
[open]="visible$ | async">
<div class="ant-popover" [ngClass]="_classMap" [ngStyle]="nzOverlayStyle" [@fadeAnimation]="''+(visible$ | async)"
(@fadeAnimation.done)="_afterVisibilityAnimation($event)">
<div class="ant-popover-content">
<div class="ant-popover-arrow"></div>
Expand Down Expand Up @@ -81,7 +82,7 @@ export class NzPopconfirmComponent extends NzToolTipComponent {

show(): void {
if (!this._condition) {
this._visible = true;
this.nzVisible = true;
} else {
this.onConfirm();
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/popover/nz-popover.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { NzToolTipComponent } from '../tooltip/nz-tooltip.component';
(detach)="hide()"
(positionChange)="onPositionChange($event)"
[positions]="_positions"
[open]="nzVisible">
<div class="ant-popover" [ngClass]="_classMap" [ngStyle]="nzOverlayStyle" [@fadeAnimation]="''+nzVisible"
[open]="visible$ | async">
<div class="ant-popover" [ngClass]="_classMap" [ngStyle]="nzOverlayStyle" [@fadeAnimation]="''+(visible$ | async)"
(@fadeAnimation.done)="_afterVisibilityAnimation($event)">
<div class="ant-popover-content">
<div class="ant-popover-arrow"></div>
Expand Down
20 changes: 12 additions & 8 deletions src/components/tooltip/nz-tooltip.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
ContentChild,
ViewChild
} from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
import { NzTooltipDirective } from './nz-tooltip.directive';
import {
AnimationEvent,
Expand Down Expand Up @@ -39,8 +41,8 @@ import { POSITION_MAP, DEFAULT_4_POSITIONS } from '../core/overlay/overlay-posit
(detach)="hide()"
(positionChange)="onPositionChange($event)"
[positions]="_positions"
[open]="nzVisible">
<div class="ant-tooltip" [ngClass]="_classMap" [ngStyle]="nzOverlayStyle" [@fadeAnimation]="''+nzVisible"
[open]="visible$ | async">
<div class="ant-tooltip" [ngClass]="_classMap" [ngStyle]="nzOverlayStyle" [@fadeAnimation]="''+(visible$ | async)"
(@fadeAnimation.done)="_afterVisibilityAnimation($event)">
<div class="ant-tooltip-content">
<div class="ant-tooltip-arrow"></div>
Expand Down Expand Up @@ -70,15 +72,18 @@ export class NzToolTipComponent implements AfterViewInit {

@Input()
set nzVisible(value) {
this._visible = value;
if (this._visible !== value) {
if (this.visibleSource.value !== value) {
this.visibleSource.next(value);
this.nzVisibleChange.emit(value);
}
};

get nzVisible() {
return this._visible;
return this.visibleSource.value;
}

visibleSource = new BehaviorSubject<boolean>(false);
visible$ = this.visibleSource.asObservable();

@Input()
set nzTrigger(value) {
Expand All @@ -96,7 +101,6 @@ export class NzToolTipComponent implements AfterViewInit {
_placement = 'top';
_trigger = 'hover';
_hasBackdrop = false;
_visible = false;

@Input()
get nzPlacement() {
Expand Down Expand Up @@ -130,12 +134,12 @@ export class NzToolTipComponent implements AfterViewInit {
}

show(): void {
this._visible = true;
this.nzVisible = true;
this.nzOrigin.isTooltipOpen = true;
}

hide(): void {
this._visible = false;
this.nzVisible = false;
this.nzOrigin.isTooltipOpen = false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy } from '@angular/core';

@Component({
selector : 'nz-demo-popconfirm',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl : './nz-demo-popconfirm.html'
})

Expand Down
3 changes: 2 additions & 1 deletion src/showcase/nz-demo-popover/nz-demo-popover.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy } from '@angular/core';

@Component({
selector : 'nz-demo-popover',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl : './nz-demo-popover.html'
})

Expand Down
3 changes: 2 additions & 1 deletion src/showcase/nz-demo-tooltip/nz-demo-tooltip.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy } from '@angular/core';
@Component({
selector : 'nz-demo-tooltip',
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl : './nz-demo-tooltip.html',
styleUrls : [
'./nz-demo-tooltip.less',
Expand Down

0 comments on commit db60e48

Please sign in to comment.