Skip to content

Commit

Permalink
perf(all): improve rxjs imports (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
trotyl authored and vthinkxie committed Aug 19, 2017
1 parent b914afd commit f3aa2cb
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/components/dropdown/nz-dropdown-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EventEmitter,
AfterViewInit
} from '@angular/core';
import { debounceTime } from 'rxjs/operator/debounceTime';
import { DropDownAnimation } from '../core/animation/dropdown-animations';
import { NzDropDownDirective } from './nz-dropdown.directive';
import { NzDropDownComponent } from './nz-dropdown.component';
Expand Down Expand Up @@ -74,7 +75,7 @@ export class NzDropDownButtonComponent extends NzDropDownComponent implements On
@ViewChild(NzDropDownDirective) _nzOrigin;

ngOnInit() {
this._$mouseSubject.debounceTime(300).subscribe((data: boolean) => {
debounceTime.call(this._$mouseSubject, 300).subscribe((data: boolean) => {
if (this.nzDisable) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/dropdown/nz-dropdown.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
Output,
EventEmitter, AfterViewInit
} from '@angular/core';
import { Subject } from 'rxjs/Rx';
import { Subject } from 'rxjs/Subject';
import { debounceTime } from 'rxjs/operator/debounceTime';
import { NzMenuComponent } from '../menu/nz-menu.component';
import { DropDownAnimation } from '../core/animation/dropdown-animations';
import { NzDropDownDirective } from './nz-dropdown.directive';
Expand Down Expand Up @@ -120,7 +121,7 @@ export class NzDropDownComponent implements OnInit, OnDestroy, AfterViewInit {
}

ngOnInit() {
this._$mouseSubject.debounceTime(300).subscribe((data: boolean) => {
debounceTime.call(this._$mouseSubject, 300).subscribe((data: boolean) => {
this.nzVisible = data;
if (this.nzVisible) {
if (!this._triggerWidth) {
Expand Down
5 changes: 3 additions & 2 deletions src/components/menu/nz-submenu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
} from '@angular/core';
import { style, animate, state, transition, trigger } from '@angular/animations';
import { NzMenuComponent } from './nz-menu.component';
import { Subject } from 'rxjs/Rx';
import { Subject } from 'rxjs/Subject';
import { debounceTime } from 'rxjs/operator/debounceTime';

@Component({
selector : '[nz-submenu]',
Expand Down Expand Up @@ -144,7 +145,7 @@ export class NzSubMenuComponent implements OnInit, OnDestroy, AfterViewInit {
}

ngOnInit() {
this._$mouseSubject.debounceTime(300).subscribe((data: boolean) => {
debounceTime.call(this._$mouseSubject, 300).subscribe((data: boolean) => {
this.nzOpen = data;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/nz-modal-subject.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Rx';
import { Subject } from 'rxjs/Subject';

/* modal的事件枚举 */
const enum modalEvent {
Expand Down
47 changes: 28 additions & 19 deletions src/components/slider/nz-slider.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ import {
forwardRef,
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { RxChain } from '@angular/cdk'
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { fromEvent } from 'rxjs/observable/fromEvent';
import { merge } from 'rxjs/observable/merge';
import { distinctUntilChanged } from 'rxjs/operator/distinctUntilChanged';
import { _do as doOperator } from 'rxjs/operator/do';
import { filter as filterOperator } from 'rxjs/operator/filter';
import { map } from 'rxjs/operator/map';
import { pluck } from 'rxjs/operator/pluck';
import { takeUntil } from 'rxjs/operator/takeUntil';
import { NzSliderService } from './nz-slider.service';
import { Marks, MarksArray } from './nz-slider-marks.component';

Expand Down Expand Up @@ -365,32 +374,32 @@ export class NzSliderComponent implements ControlValueAccessor, OnInit, OnChange
[ mouse, touch ].forEach(source => {
const { start, move, end, pluckKey, filter = () => true } = source;
// start
source.startPlucked$ = Observable
.fromEvent(sliderDOM, start)
.filter(<any>filter)
.do(this.utils.pauseEvent)
.pluck(...pluckKey)
.map((position: number) => this.findClosestValue(position));
source.startPlucked$ = (RxChain.from(fromEvent(sliderDOM, start)) as RxChain<any>)
.call(filterOperator, filter)
.call(doOperator, this.utils.pauseEvent)
.call(pluck, ...pluckKey)
.call(map, (position: number) => this.findClosestValue(position))
.result();
// end
source.end$ = Observable.fromEvent(document, end);
source.end$ = fromEvent(document, end);
// resolve move
source.moveResolved$ = Observable
.fromEvent(document, move)
.filter(<any>filter)
.do(this.utils.pauseEvent)
.pluck(...pluckKey)
.distinctUntilChanged()
.map((position: number) => this.findClosestValue(position))
.distinctUntilChanged()
.takeUntil(source.end$);
source.moveResolved$ = (RxChain.from(fromEvent(document, move)) as RxChain<any>)
.call(filterOperator, filter)
.call(doOperator, this.utils.pauseEvent)
.call(pluck, ...pluckKey)
.call(distinctUntilChanged)
.call(map, (position: number) => this.findClosestValue(position))
.call(distinctUntilChanged)
.call(takeUntil, source.end$)
.result();
// merge to become moving
// source.move$ = source.startPlucked$.mergeMapTo(source.moveResolved$);
});
// merge mouse and touch observables
this.dragstart$ = Observable.merge(mouse.startPlucked$, touch.startPlucked$);
this.dragstart$ = merge(mouse.startPlucked$, touch.startPlucked$);
// this.dragmove$ = Observable.merge(mouse.move$, touch.move$);
this.dragmove$ = Observable.merge(mouse.moveResolved$, touch.moveResolved$);
this.dragend$ = Observable.merge(mouse.end$, touch.end$);
this.dragmove$ = merge(mouse.moveResolved$, touch.moveResolved$);
this.dragend$ = merge(mouse.end$, touch.end$);
}

subscribeDrag(periods = [ 'start', 'move', 'end' ]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
FormControl,
Validators
} from '@angular/forms';
import { Observable } from 'rxjs/Rx';
import { Observable } from 'rxjs/Observable';

@Component({
selector: 'nz-demo-form-validate-dynamic',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Jsonp, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Component({
selector: 'nz-demo-select-multiple-change',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Jsonp, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Component({
selector: 'nz-demo-select-search-change',
Expand Down
3 changes: 3 additions & 0 deletions src/showcase/nz-demo-table/randomUser.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';

@Injectable()
export class RandomUserService {
randomUserUrl = 'https://api.randomuser.me/';
Expand Down

0 comments on commit f3aa2cb

Please sign in to comment.