From b56d39198f724f2f3c647d05b2d12a9797f7933c Mon Sep 17 00:00:00 2001 From: ArushKapoorJuspay <121166031+ArushKapoorJuspay@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:11:45 +0530 Subject: [PATCH] refactor: refactored lazy loading (#484) --- src/PaymentElementRendererLazy.res | 11 +---------- src/PaymentManagementLazy.res | 5 +---- src/PaymentMethodCollectElementLazy.res | 9 +-------- src/Payments/ACHBankDebitLazy.res | 6 +----- src/Payments/ACHBankTransferLazy.res | 6 +----- src/Payments/ApplePayLazy.res | 8 +------- src/Payments/BacsBankDebitLazy.res | 6 +----- src/Payments/BacsBankTransfer.res | 3 ++- src/Payments/BacsBankTransfer.resi | 3 ++- src/Payments/BacsBankTransferLazy.res | 6 +----- src/Payments/BecsBankDebitLazy.res | 6 +----- src/Payments/BoletoLazy.res | 6 +----- src/Payments/GPayLazy.res | 9 +-------- src/Payments/KlarnaPaymentLazy.res | 6 +----- src/Payments/KlarnaSDKLazy.res | 6 +----- src/Payments/PayPalLazy.res | 6 +----- src/Payments/PaymentMethodsWrapperLazy.res | 9 +-------- src/Payments/PaypalSDKLazy.res | 6 +----- src/Payments/SepaBankDebitLazy.res | 6 +----- src/Payments/SepaBankTransferLazy.res | 6 +----- src/SingleLineCardPaymentLazy.res | 14 +------------- src/Utilities/LazyUtils.res | 11 ----------- 22 files changed, 23 insertions(+), 131 deletions(-) delete mode 100644 src/Utilities/LazyUtils.res diff --git a/src/PaymentElementRendererLazy.res b/src/PaymentElementRendererLazy.res index c49f5ca1a..233aafa9d 100644 --- a/src/PaymentElementRendererLazy.res +++ b/src/PaymentElementRendererLazy.res @@ -1,10 +1 @@ -open LazyUtils - -type props = { - paymentType: CardThemeType.mode, - cardProps: CardUtils.cardProps, - expiryProps: CardUtils.expiryProps, - cvcProps: CardUtils.cvcProps, -} - -let make: props => React.element = reactLazy(() => import_("./PaymentElementRenderer.bs.js")) +let make = React.lazy_(() => Js.import(PaymentElementRenderer.default)) diff --git a/src/PaymentManagementLazy.res b/src/PaymentManagementLazy.res index 0f893d208..fa161dfa2 100644 --- a/src/PaymentManagementLazy.res +++ b/src/PaymentManagementLazy.res @@ -1,4 +1 @@ -open LazyUtils - -type props = {} -let make: props => React.element = reactLazy(() => import_("./PaymentManagement.bs.js")) +let make = React.lazy_(() => Js.import(PaymentManagement.default)) diff --git a/src/PaymentMethodCollectElementLazy.res b/src/PaymentMethodCollectElementLazy.res index 5e7be09f0..fe013f6ca 100644 --- a/src/PaymentMethodCollectElementLazy.res +++ b/src/PaymentMethodCollectElementLazy.res @@ -1,8 +1 @@ -open LazyUtils - -type props = { - integrateError: bool, - logger: OrcaLogger.loggerMake, -} - -let make: props => React.element = reactLazy(() => import_("./PaymentMethodCollectElement.bs.js")) +let make = React.lazy_(() => Js.import(PaymentMethodCollectElement.default)) diff --git a/src/Payments/ACHBankDebitLazy.res b/src/Payments/ACHBankDebitLazy.res index 46ed49ac6..7b8e4bd7a 100644 --- a/src/Payments/ACHBankDebitLazy.res +++ b/src/Payments/ACHBankDebitLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {paymentType: CardThemeType.mode} - -let make: props => React.element = reactLazy(() => import_("./ACHBankDebit.bs.js")) +let make = React.lazy_(() => Js.import(ACHBankDebit.default)) diff --git a/src/Payments/ACHBankTransferLazy.res b/src/Payments/ACHBankTransferLazy.res index bc1f80d04..cc8b8b7df 100644 --- a/src/Payments/ACHBankTransferLazy.res +++ b/src/Payments/ACHBankTransferLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {paymentType: CardThemeType.mode} - -let make: props => React.element = reactLazy(() => import_("./ACHBankTransfer.bs.js")) +let make = React.lazy_(() => Js.import(ACHBankTransfer.default)) diff --git a/src/Payments/ApplePayLazy.res b/src/Payments/ApplePayLazy.res index 57d9d5a69..ff71cdd01 100644 --- a/src/Payments/ApplePayLazy.res +++ b/src/Payments/ApplePayLazy.res @@ -1,7 +1 @@ -open LazyUtils - -type props = { - sessionObj: option -} - -let make: props => React.element = reactLazy(() => import_("./ApplePay.bs.js")) +let make = React.lazy_(() => Js.import(ApplePay.default)) diff --git a/src/Payments/BacsBankDebitLazy.res b/src/Payments/BacsBankDebitLazy.res index a66897bfe..c75266631 100644 --- a/src/Payments/BacsBankDebitLazy.res +++ b/src/Payments/BacsBankDebitLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {paymentType: CardThemeType.mode} - -let make: props => React.element = reactLazy(() => import_("./BacsBankDebit.bs.js")) +let make = React.lazy_(() => Js.import(BacsBankDebit.default)) diff --git a/src/Payments/BacsBankTransfer.res b/src/Payments/BacsBankTransfer.res index 430edbc5a..c22e5ce8a 100644 --- a/src/Payments/BacsBankTransfer.res +++ b/src/Payments/BacsBankTransfer.res @@ -1,7 +1,8 @@ open RecoilAtoms open Utils -let default = (paymentType: CardThemeType.mode) => { +@react.component +let default = (~paymentType: CardThemeType.mode) => { let {iframeId} = Recoil.useRecoilValueFromAtom(keys) let loggerState = Recoil.useRecoilValueFromAtom(loggerAtom) let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom) diff --git a/src/Payments/BacsBankTransfer.resi b/src/Payments/BacsBankTransfer.resi index 99fa10d96..f20dac89a 100644 --- a/src/Payments/BacsBankTransfer.resi +++ b/src/Payments/BacsBankTransfer.resi @@ -1 +1,2 @@ -let default: CardThemeType.mode => React.element +@react.component +let default: (~paymentType: CardThemeType.mode) => React.element diff --git a/src/Payments/BacsBankTransferLazy.res b/src/Payments/BacsBankTransferLazy.res index 54454654d..57e09c28f 100644 --- a/src/Payments/BacsBankTransferLazy.res +++ b/src/Payments/BacsBankTransferLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {paymentType: CardThemeType.mode} - -let make: props => React.element = reactLazy(() => import_("./BacsBankTransfer.bs.js")) +let make = React.lazy_(() => Js.import(BacsBankTransfer.default)) diff --git a/src/Payments/BecsBankDebitLazy.res b/src/Payments/BecsBankDebitLazy.res index 329665952..12c595fb5 100644 --- a/src/Payments/BecsBankDebitLazy.res +++ b/src/Payments/BecsBankDebitLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {paymentType: CardThemeType.mode} - -let make: props => React.element = reactLazy(() => import_("./BecsBankDebit.bs.js")) +let make = React.lazy_(() => Js.import(BecsBankDebit.default)) diff --git a/src/Payments/BoletoLazy.res b/src/Payments/BoletoLazy.res index 86f2e2254..1ae7665a2 100644 --- a/src/Payments/BoletoLazy.res +++ b/src/Payments/BoletoLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {paymentType: CardThemeType.mode} - -let make: props => React.element = reactLazy(() => import_("./Boleto.bs.js")) +let make = React.lazy_(() => Js.import(Boleto.default)) diff --git a/src/Payments/GPayLazy.res b/src/Payments/GPayLazy.res index c291d2fe6..215a868dd 100644 --- a/src/Payments/GPayLazy.res +++ b/src/Payments/GPayLazy.res @@ -1,8 +1 @@ -open LazyUtils - -type props = { - sessionObj: option, - thirdPartySessionObj: option, -} - -let make: props => React.element = reactLazy(() => import_("./GPay.bs.js")) +let make = React.lazy_(() => Js.import(GPay.default)) diff --git a/src/Payments/KlarnaPaymentLazy.res b/src/Payments/KlarnaPaymentLazy.res index a2a1d95cd..411e574e5 100644 --- a/src/Payments/KlarnaPaymentLazy.res +++ b/src/Payments/KlarnaPaymentLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {paymentType: CardThemeType.mode} - -let make: props => React.element = reactLazy(() => import_("./KlarnaPayment.bs.js")) +let make = React.lazy_(() => Js.import(KlarnaPayment.default)) diff --git a/src/Payments/KlarnaSDKLazy.res b/src/Payments/KlarnaSDKLazy.res index 3a530eeef..e56a28717 100644 --- a/src/Payments/KlarnaSDKLazy.res +++ b/src/Payments/KlarnaSDKLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {sessionObj: SessionsType.token} - -let make: props => React.element = reactLazy(() => import_("./KlarnaSDK.bs.js")) +let make = React.lazy_(() => Js.import(KlarnaSDK.default)) diff --git a/src/Payments/PayPalLazy.res b/src/Payments/PayPalLazy.res index ccf657148..fbc63c2d6 100644 --- a/src/Payments/PayPalLazy.res +++ b/src/Payments/PayPalLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {} - -let make: props => React.element = reactLazy(() => import_("./PayPal.bs.js")) +let make = React.lazy_(() => Js.import(PayPal.default)) diff --git a/src/Payments/PaymentMethodsWrapperLazy.res b/src/Payments/PaymentMethodsWrapperLazy.res index 19cb39d6d..f28e3c5c9 100644 --- a/src/Payments/PaymentMethodsWrapperLazy.res +++ b/src/Payments/PaymentMethodsWrapperLazy.res @@ -1,8 +1 @@ -open LazyUtils - -type props = { - paymentType: CardThemeType.mode, - paymentMethodName: string, -} - -let make: props => React.element = reactLazy(() => import_("./PaymentMethodsWrapper.bs.js")) +let make = React.lazy_(() => Js.import(PaymentMethodsWrapper.default)) diff --git a/src/Payments/PaypalSDKLazy.res b/src/Payments/PaypalSDKLazy.res index 9d978b196..609f54036 100644 --- a/src/Payments/PaypalSDKLazy.res +++ b/src/Payments/PaypalSDKLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {sessionObj: SessionsType.token, paymentType: CardThemeType.mode} - -let make: props => React.element = reactLazy(() => import_("./PaypalSDK.bs.js")) +let make = React.lazy_(() => Js.import(PaypalSDK.default)) diff --git a/src/Payments/SepaBankDebitLazy.res b/src/Payments/SepaBankDebitLazy.res index 8c936e9c6..9cb6b2dc3 100644 --- a/src/Payments/SepaBankDebitLazy.res +++ b/src/Payments/SepaBankDebitLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {paymentType: CardThemeType.mode} - -let make: props => React.element = reactLazy(() => import_("./SepaBankDebit.bs.js")) +let make = React.lazy_(() => Js.import(SepaBankDebit.default)) diff --git a/src/Payments/SepaBankTransferLazy.res b/src/Payments/SepaBankTransferLazy.res index c49f82aa9..e658939f1 100644 --- a/src/Payments/SepaBankTransferLazy.res +++ b/src/Payments/SepaBankTransferLazy.res @@ -1,5 +1 @@ -open LazyUtils - -type props = {paymentType: CardThemeType.mode} - -let make: props => React.element = reactLazy(() => import_("./SepaBankTransfer.bs.js")) +let make = React.lazy_(() => Js.import(SepaBankTransfer.default)) diff --git a/src/SingleLineCardPaymentLazy.res b/src/SingleLineCardPaymentLazy.res index 312cec600..35f08c099 100644 --- a/src/SingleLineCardPaymentLazy.res +++ b/src/SingleLineCardPaymentLazy.res @@ -1,13 +1 @@ -open LazyUtils - -type props = { - paymentType: CardThemeType.mode, - cardProps: CardUtils.cardProps, - expiryProps: CardUtils.expiryProps, - cvcProps: CardUtils.cvcProps, - zipProps: CardUtils.zipProps, - handleElementFocus: bool => unit, - isFocus: bool, -} - -let make: props => React.element = reactLazy(() => import_("./SingleLineCardPayment.bs.js")) +let make = React.lazy_(() => Js.import(SingleLineCardPayment.default)) diff --git a/src/Utilities/LazyUtils.res b/src/Utilities/LazyUtils.res deleted file mode 100644 index 402767640..000000000 --- a/src/Utilities/LazyUtils.res +++ /dev/null @@ -1,11 +0,0 @@ -type lazyScreen - -type lazyScreenLoader = unit => Promise.t - -@val -external import_: string => Promise.t = "import" - -type reactLazy<'component> = lazyScreenLoader => 'component - -@module("react") @val -external reactLazy: reactLazy<'a> = "lazy"