Skip to content

Commit

Permalink
refactor(picker): using DomController
Browse files Browse the repository at this point in the history
Removed NativeRafDebouncer
  • Loading branch information
manucorporat committed Dec 2, 2016
1 parent c08c21a commit 24d45d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 46 deletions.
10 changes: 6 additions & 4 deletions src/components/picker/picker-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { Picker } from './picker';
import { PickerOptions, PickerColumn, PickerColumnOption } from './picker-options';
import { Haptic } from '../../util/haptic';
import { UIEventManager } from '../../util/ui-event-manager';
import { DomController, DomDebouncer } from '../../util/dom-controller';
import { ViewController } from '../../navigation/view-controller';
import { Debouncer, NativeRafDebouncer } from '../../util/debouncer';
import { GestureController, BlockerDelegate, BLOCK_ALL } from '../../gestures/gesture-controller';

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ export class PickerColumnCmp {
lastIndex: number;
lastTempIndex: number;
decelerateFunc: Function;
debouncer: Debouncer = new NativeRafDebouncer();
debouncer: DomDebouncer;
events: UIEventManager = new UIEventManager(false);

@Output() ionChange: EventEmitter<any> = new EventEmitter();
Expand All @@ -63,11 +63,13 @@ export class PickerColumnCmp {
private elementRef: ElementRef,
private _sanitizer: DomSanitizer,
private _zone: NgZone,
private _haptic: Haptic
private _haptic: Haptic,
domCtrl: DomController,
) {
this.rotateFactor = config.getNumber('pickerRotateFactor', 0);
this.scaleFactor = config.getNumber('pickerScaleFactor', 1);
this.decelerateFunc = this.decelerate.bind(this);
this.debouncer = domCtrl.debouncer();
}

ngAfterViewInit() {
Expand Down Expand Up @@ -145,7 +147,7 @@ export class PickerColumnCmp {
let currentY = pointerCoord(ev).y;
this.pos.push(currentY, Date.now());

this.debouncer.debounce(() => {
this.debouncer.write(() => {
if (this.startY === null) {
return;
}
Expand Down
42 changes: 0 additions & 42 deletions src/util/debouncer.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@

import { nativeRaf } from './dom';

export interface Debouncer {
debounce(Function);
cancel();
}


export class FakeDebouncer implements Debouncer {
debounce(callback: Function) {
callback();
}
cancel() {}
}

export class TimeoutDebouncer implements Debouncer {
private timer: number = null;
callback: Function;
Expand Down Expand Up @@ -42,36 +33,3 @@ export class TimeoutDebouncer implements Debouncer {
}

}

export class NativeRafDebouncer implements Debouncer {
callback: Function = null;
fireFunc: Function;
ptr: number = null;

constructor() {
this.fireFunc = this.fire.bind(this);
}

debounce(callback: Function) {
if (this.callback === null) {
this.callback = callback;
this.ptr = nativeRaf(this.fireFunc);
}
}

fire() {
this.callback();
this.callback = null;
this.ptr = null;
}

cancel() {
if (this.ptr !== null) {
cancelAnimationFrame(this.ptr);
this.ptr = null;
this.callback = null;
}
}

}

0 comments on commit 24d45d5

Please sign in to comment.