From b0c8780a0fb3ccf27f0557ebfe1ceb27efc6b3af Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Fri, 2 Feb 2024 15:30:40 +0000 Subject: [PATCH 1/7] [TS migration] Migrate react-native-onyx mock --- __mocks__/react-native-onyx.js | 27 --------------------------- __mocks__/react-native-onyx.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 27 deletions(-) delete mode 100644 __mocks__/react-native-onyx.js create mode 100644 __mocks__/react-native-onyx.ts diff --git a/__mocks__/react-native-onyx.js b/__mocks__/react-native-onyx.js deleted file mode 100644 index d44c73e824d3..000000000000 --- a/__mocks__/react-native-onyx.js +++ /dev/null @@ -1,27 +0,0 @@ -/* eslint-disable rulesdir/prefer-onyx-connect-in-libs */ -import Onyx, {withOnyx} from 'react-native-onyx'; - -let connectCallbackDelay = 0; -function addDelayToConnectCallback(delay) { - connectCallbackDelay = delay; -} - -export default { - ...Onyx, - connect: (mapping) => - Onyx.connect({ - ...mapping, - callback: (...params) => { - if (connectCallbackDelay > 0) { - setTimeout(() => { - mapping.callback(...params); - }, connectCallbackDelay); - } else { - mapping.callback(...params); - } - }, - }), - addDelayToConnectCallback, -}; -export {withOnyx}; -/* eslint-enable rulesdir/prefer-onyx-connect-in-libs */ diff --git a/__mocks__/react-native-onyx.ts b/__mocks__/react-native-onyx.ts new file mode 100644 index 000000000000..6d59d2ec66e9 --- /dev/null +++ b/__mocks__/react-native-onyx.ts @@ -0,0 +1,34 @@ +/* eslint-disable rulesdir/prefer-onyx-connect-in-libs */ +import Onyx, {ConnectOptions, OnyxEntry, OnyxKey, withOnyx} from 'react-native-onyx'; +import { OnyxCollection } from 'react-native-onyx/dist/types'; + +let connectCallbackDelay = 0; +function addDelayToConnectCallback(delay: number) { + connectCallbackDelay = delay; +} + +type ReactNativeOnyxMock = { + addDelayToConnectCallback: (delay: number) => void +} & typeof Onyx + +const reactNativeOnyxMock: ReactNativeOnyxMock = { + ...Onyx, + connect: (mapping: ConnectOptions) => + Onyx.connect({ + ...mapping, + callback: (value: OnyxEntry | OnyxCollection, key?: TKey) => { + if (connectCallbackDelay > 0) { + setTimeout(() => { + (mapping.callback as (value: OnyxEntry | OnyxCollection, key?: TKey) => void)?.(value, key) + }, connectCallbackDelay); + } else { + (mapping.callback as (value: OnyxEntry | OnyxCollection, key?: TKey) => void)?.(value, key); + } + }, + }), + addDelayToConnectCallback, +} + +export default reactNativeOnyxMock +export {withOnyx}; +/* eslint-enable rulesdir/prefer-onyx-connect-in-libs */ From 20ad77bc48f9d5ee1fbcead1e1da79974ae829e8 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Mon, 5 Feb 2024 16:23:28 +0000 Subject: [PATCH 2/7] [TS migration][react-native-onyx mock] Addressed suggestion --- __mocks__/react-native-onyx.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/__mocks__/react-native-onyx.ts b/__mocks__/react-native-onyx.ts index 6d59d2ec66e9..89491e589a21 100644 --- a/__mocks__/react-native-onyx.ts +++ b/__mocks__/react-native-onyx.ts @@ -1,6 +1,6 @@ /* eslint-disable rulesdir/prefer-onyx-connect-in-libs */ -import Onyx, {ConnectOptions, OnyxEntry, OnyxKey, withOnyx} from 'react-native-onyx'; -import { OnyxCollection } from 'react-native-onyx/dist/types'; +import type {ConnectOptions, OnyxKey} from 'react-native-onyx'; +import Onyx, { withOnyx} from 'react-native-onyx'; let connectCallbackDelay = 0; function addDelayToConnectCallback(delay: number) { @@ -8,27 +8,32 @@ function addDelayToConnectCallback(delay: number) { } type ReactNativeOnyxMock = { - addDelayToConnectCallback: (delay: number) => void -} & typeof Onyx + addDelayToConnectCallback: (delay: number) => void; +} & typeof Onyx; + +type ConnectionCallback = NonNullable['callback']>; +type ConnectionCallbackParams = Parameters>; const reactNativeOnyxMock: ReactNativeOnyxMock = { ...Onyx, - connect: (mapping: ConnectOptions) => - Onyx.connect({ - ...mapping, - callback: (value: OnyxEntry | OnyxCollection, key?: TKey) => { + connect: (mapping: ConnectOptions) => { + const callback = (...params: ConnectionCallbackParams) => { if (connectCallbackDelay > 0) { setTimeout(() => { - (mapping.callback as (value: OnyxEntry | OnyxCollection, key?: TKey) => void)?.(value, key) + (mapping.callback as (...args: ConnectionCallbackParams) => void)?.(...params); }, connectCallbackDelay); } else { - (mapping.callback as (value: OnyxEntry | OnyxCollection, key?: TKey) => void)?.(value, key); + (mapping.callback as (...args: ConnectionCallbackParams) => void)?.(...params); } - }, - }), + }; + return Onyx.connect({ + ...mapping, + callback, + }); + }, addDelayToConnectCallback, -} +}; -export default reactNativeOnyxMock +export default reactNativeOnyxMock; export {withOnyx}; /* eslint-enable rulesdir/prefer-onyx-connect-in-libs */ From ffebb9cdfaf2920787c864a9ec5bb25869c9e542 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Wed, 7 Feb 2024 08:37:47 +0000 Subject: [PATCH 3/7] [TS migration][react-native-onyx-mock] Fixed lint --- __mocks__/react-native-onyx.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/__mocks__/react-native-onyx.ts b/__mocks__/react-native-onyx.ts index 89491e589a21..beed7be9cbdf 100644 --- a/__mocks__/react-native-onyx.ts +++ b/__mocks__/react-native-onyx.ts @@ -1,6 +1,6 @@ /* eslint-disable rulesdir/prefer-onyx-connect-in-libs */ import type {ConnectOptions, OnyxKey} from 'react-native-onyx'; -import Onyx, { withOnyx} from 'react-native-onyx'; +import Onyx, {withOnyx} from 'react-native-onyx'; let connectCallbackDelay = 0; function addDelayToConnectCallback(delay: number) { @@ -36,4 +36,3 @@ const reactNativeOnyxMock: ReactNativeOnyxMock = { export default reactNativeOnyxMock; export {withOnyx}; -/* eslint-enable rulesdir/prefer-onyx-connect-in-libs */ From b5b642b4f2dfaecf4acd7b9805f3e004be1126b2 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Wed, 14 Feb 2024 12:27:42 +0000 Subject: [PATCH 4/7] [TS migration][react-native-onyx] Added comment on the disabled rule --- __mocks__/react-native-onyx.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/__mocks__/react-native-onyx.ts b/__mocks__/react-native-onyx.ts index beed7be9cbdf..2a172f818b5f 100644 --- a/__mocks__/react-native-onyx.ts +++ b/__mocks__/react-native-onyx.ts @@ -1,3 +1,8 @@ +/** + * We are disabling the lint rule that doesn't allow the usage of connect onyx outside libs + * because the intent of this file is to mock the usage of react-native-onyx so we will have to mock the connect function + * as this is a file outside of the lib folder we need to disable it + */ /* eslint-disable rulesdir/prefer-onyx-connect-in-libs */ import type {ConnectOptions, OnyxKey} from 'react-native-onyx'; import Onyx, {withOnyx} from 'react-native-onyx'; From 52408bbf09afdf9d1a66a825eb182415ff4f2bdb Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Wed, 14 Feb 2024 12:33:10 +0000 Subject: [PATCH 5/7] [TS migration][react-native-onyx] Prettier run --- __mocks__/react-native-onyx.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/__mocks__/react-native-onyx.ts b/__mocks__/react-native-onyx.ts index 2a172f818b5f..d403000191b1 100644 --- a/__mocks__/react-native-onyx.ts +++ b/__mocks__/react-native-onyx.ts @@ -3,6 +3,7 @@ * because the intent of this file is to mock the usage of react-native-onyx so we will have to mock the connect function * as this is a file outside of the lib folder we need to disable it */ + /* eslint-disable rulesdir/prefer-onyx-connect-in-libs */ import type {ConnectOptions, OnyxKey} from 'react-native-onyx'; import Onyx, {withOnyx} from 'react-native-onyx'; From 83a5b3b59a1faf4f931dce4e53de48e92913143c Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Tue, 20 Feb 2024 12:40:55 +0000 Subject: [PATCH 6/7] [TS migration][react-native-onyx] Feedback addressed --- __mocks__/react-native-onyx.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/__mocks__/react-native-onyx.ts b/__mocks__/react-native-onyx.ts index d403000191b1..55690accc016 100644 --- a/__mocks__/react-native-onyx.ts +++ b/__mocks__/react-native-onyx.ts @@ -1,9 +1,7 @@ /** - * We are disabling the lint rule that doesn't allow the usage of connect onyx outside libs + * We are disabling the lint rule that doesn't allow the usage of Onyx.connect outside libs * because the intent of this file is to mock the usage of react-native-onyx so we will have to mock the connect function - * as this is a file outside of the lib folder we need to disable it */ - /* eslint-disable rulesdir/prefer-onyx-connect-in-libs */ import type {ConnectOptions, OnyxKey} from 'react-native-onyx'; import Onyx, {withOnyx} from 'react-native-onyx'; From 7fdbd4b7250a6590f5332794d2be8ab25a9d00d0 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Tue, 20 Feb 2024 12:50:12 +0000 Subject: [PATCH 7/7] [TS migration] Prettier run --- __mocks__/react-native-onyx.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/__mocks__/react-native-onyx.ts b/__mocks__/react-native-onyx.ts index 55690accc016..253e3db47a96 100644 --- a/__mocks__/react-native-onyx.ts +++ b/__mocks__/react-native-onyx.ts @@ -2,6 +2,7 @@ * We are disabling the lint rule that doesn't allow the usage of Onyx.connect outside libs * because the intent of this file is to mock the usage of react-native-onyx so we will have to mock the connect function */ + /* eslint-disable rulesdir/prefer-onyx-connect-in-libs */ import type {ConnectOptions, OnyxKey} from 'react-native-onyx'; import Onyx, {withOnyx} from 'react-native-onyx';