refactor(haptic): pure module

This commit is contained in:
Manu Mtz.-Almeida
2018-04-08 17:18:07 +02:00
parent fcb08e1642
commit 5f9b74ca38

View File

@@ -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);
}