From 4ef3d7437b4e0a6068a0beb410843b0900d58c3f Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Mon, 23 Oct 2023 12:12:11 -0400 Subject: [PATCH] REF: JS modules to TS --- __mocks__/react-native-image-picker.js | 2 +- blue_modules/constants.js | 5 ----- blue_modules/constants.ts | 5 +++++ blue_modules/debounce.js | 14 -------------- blue_modules/debounce.ts | 16 ++++++++++++++++ 5 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 blue_modules/constants.js create mode 100644 blue_modules/constants.ts delete mode 100644 blue_modules/debounce.js create mode 100644 blue_modules/debounce.ts diff --git a/__mocks__/react-native-image-picker.js b/__mocks__/react-native-image-picker.js index 3392a0e6b..c401aabe3 100644 --- a/__mocks__/react-native-image-picker.js +++ b/__mocks__/react-native-image-picker.js @@ -1,4 +1,4 @@ -import {NativeModules} from 'react-native'; +import { NativeModules } from 'react-native'; // Mock the ImagePickerManager native module to allow us to unit test the JavaScript code NativeModules.ImagePickerManager = { diff --git a/blue_modules/constants.js b/blue_modules/constants.js deleted file mode 100644 index 3066fb6b3..000000000 --- a/blue_modules/constants.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Let's keep config vars, constants and definitions here - */ - -export const groundControlUri = 'https://groundcontrol-bluewallet.herokuapp.com/'; diff --git a/blue_modules/constants.ts b/blue_modules/constants.ts new file mode 100644 index 000000000..e2a0e1649 --- /dev/null +++ b/blue_modules/constants.ts @@ -0,0 +1,5 @@ +/** + * Let's keep config vars, constants and definitions here + */ + +export const groundControlUri: string = 'https://groundcontrol-bluewallet.herokuapp.com/'; diff --git a/blue_modules/debounce.js b/blue_modules/debounce.js deleted file mode 100644 index dacfdfefd..000000000 --- a/blue_modules/debounce.js +++ /dev/null @@ -1,14 +0,0 @@ -// https://levelup.gitconnected.com/debounce-in-javascript-improve-your-applications-performance-5b01855e086 -const debounce = (func, wait) => { - let timeout; - return function executedFunction(...args) { - const later = () => { - timeout = null; - func(...args); - }; - clearTimeout(timeout); - timeout = setTimeout(later, wait); - }; -}; - -export default debounce; diff --git a/blue_modules/debounce.ts b/blue_modules/debounce.ts new file mode 100644 index 000000000..99742cec2 --- /dev/null +++ b/blue_modules/debounce.ts @@ -0,0 +1,16 @@ +// https://levelup.gitconnected.com/debounce-in-javascript-improve-your-applications-performance-5b01855e086 +const debounce = void>(func: T, wait: number) => { + let timeout: NodeJS.Timeout | null; + return function executedFunction(this: ThisParameterType, ...args: Parameters) { + const later = () => { + timeout = null; + func.apply(this, args); + }; + if (timeout) { + clearTimeout(timeout); + } + timeout = setTimeout(later, wait); + }; +}; + +export default debounce;