From 24d45d5c50cd9b7ba31a9deb64791f6583d98d83 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Fri, 2 Dec 2016 11:52:39 +0100 Subject: [PATCH] refactor(picker): using DomController Removed NativeRafDebouncer --- src/components/picker/picker-component.ts | 10 +++--- src/util/debouncer.ts | 42 ----------------------- 2 files changed, 6 insertions(+), 46 deletions(-) diff --git a/src/components/picker/picker-component.ts b/src/components/picker/picker-component.ts index c28db440cc9..c7c897c1feb 100644 --- a/src/components/picker/picker-component.ts +++ b/src/components/picker/picker-component.ts @@ -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'; /** @@ -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 = new EventEmitter(); @@ -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() { @@ -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; } diff --git a/src/util/debouncer.ts b/src/util/debouncer.ts index de3932a9386..91690094fd9 100644 --- a/src/util/debouncer.ts +++ b/src/util/debouncer.ts @@ -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; @@ -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; - } - } - -} -