From 5f9b74ca38ebb94a554040341eeaecb31288116b Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Sun, 8 Apr 2018 17:18:07 +0200 Subject: [PATCH] refactor(haptic): pure module --- core/src/utils/haptic.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/src/utils/haptic.ts b/core/src/utils/haptic.ts index 2d0690199d..586d07e5fa 100644 --- a/core/src/utils/haptic.ts +++ b/core/src/utils/haptic.ts @@ -1,11 +1,9 @@ -const engine = (window as any).TapticEngine; - /** * Check to see if the Haptic Plugin is available - * @return {boolean} Returns true or false if the plugin is available - * + * @return Returns true or false if the plugin is available */ -export function hapticAvailable() { +export function hapticAvailable(): boolean { + const engine = (window as any).TapticEngine; return !!engine; } @@ -14,6 +12,7 @@ export function hapticAvailable() { * (not for gestures) */ export function hapticSelection() { + const engine = (window as any).TapticEngine; engine && engine.selection(); } @@ -21,6 +20,7 @@ export function hapticSelection() { * Tell the haptic engine that a gesture for a selection change is starting. */ export function hapticSelectionStart() { + const engine = (window as any).TapticEngine; engine && engine.gestureSelectionStart(); } @@ -28,6 +28,7 @@ export function hapticSelectionStart() { * Tell the haptic engine that a selection changed during a gesture. */ export function hapticSelectionChanged() { + const engine = (window as any).TapticEngine; engine && engine.gestureSelectionChanged(); } @@ -36,6 +37,7 @@ export function hapticSelectionChanged() { * called lest resources are not properly recycled. */ export function hapticSelectionEnd() { + const engine = (window as any).TapticEngine; engine && engine.gestureSelectionEnd(); } @@ -44,6 +46,7 @@ export function hapticSelectionEnd() { * options should be of the type `{ type: 'success' }` (or `warning`/`error`) */ export function hapticNotification(options: { type: string }) { + const engine = (window as any).TapticEngine; engine && engine.notification(options); } @@ -52,5 +55,6 @@ export function hapticNotification(options: { type: string }) { * options should be of the type `{ style: 'light' }` (or `medium`/`heavy`) */ export function hapticImpact(options: { style: string }) { + const engine = (window as any).TapticEngine; engine && engine.impact(options); }