Improve code structure
This commit is contained in:
parent
cb043aec01
commit
8ec3fd335e
1 changed files with 21 additions and 36 deletions
57
README.md
57
README.md
|
@ -57,7 +57,7 @@ const triggerEmailCampaign = ({
|
||||||
pipe(
|
pipe(
|
||||||
user.nationality === 'FR',
|
user.nationality === 'FR',
|
||||||
boolean.match(
|
boolean.match(
|
||||||
() => triggerGlobalEmailCampain({ to: user.email, emailSettings }),
|
() => triggerGlobalEmailCampaign({ to: user.email, emailSettings }),
|
||||||
() => triggerFrenchEmailCampaign({ to: user.email, emailSettings }),
|
() => triggerFrenchEmailCampaign({ to: user.email, emailSettings }),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -70,7 +70,7 @@ const triggerEmailCampaign = ({
|
||||||
if (user.nationality === 'FR') {
|
if (user.nationality === 'FR') {
|
||||||
return triggerFrenchEmailCampaign({ to: user.email, emailSettings });
|
return triggerFrenchEmailCampaign({ to: user.email, emailSettings });
|
||||||
}
|
}
|
||||||
return triggerGlobalEmailCampain({ to: user.email, emailSettings });
|
return triggerGlobalEmailCampaign({ to: user.email, emailSettings });
|
||||||
```
|
```
|
||||||
|
|
||||||
- Avoid nested pipes
|
- Avoid nested pipes
|
||||||
|
@ -78,7 +78,7 @@ const triggerEmailCampaign = ({
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// Bad
|
// Bad
|
||||||
const convertDollarAmountInCountryCurrency = ({
|
export const convertDollarAmountInCountryCurrency = ({
|
||||||
countryName,
|
countryName,
|
||||||
amountInDollar,
|
amountInDollar,
|
||||||
}: {
|
}: {
|
||||||
|
@ -91,10 +91,9 @@ const convertDollarAmountInCountryCurrency = ({
|
||||||
countryCode =>
|
countryCode =>
|
||||||
pipe(
|
pipe(
|
||||||
getCountryCurrency(countryCode),
|
getCountryCurrency(countryCode),
|
||||||
option.map(currency =>
|
option.map(
|
||||||
pipe(
|
flow(
|
||||||
amountInDollar,
|
convertFromDollarAmount(amountInDollar),
|
||||||
converFromDollar(currency),
|
|
||||||
convertedAmount =>
|
convertedAmount =>
|
||||||
console.log(
|
console.log(
|
||||||
`converted amount for country ${countryCode} is ${convertedAmount}`,
|
`converted amount for country ${countryCode} is ${convertedAmount}`,
|
||||||
|
@ -107,35 +106,21 @@ const convertDollarAmountInCountryCurrency = ({
|
||||||
);
|
);
|
||||||
|
|
||||||
// Good
|
// Good
|
||||||
const convertDollarAmountInCountryCodeCurrency = ({
|
export const convertDollarAmountInCountryCurrency = (amountInDollar: number) =>
|
||||||
amountInDollar,
|
flow(
|
||||||
countryCode,
|
getCountryCode,
|
||||||
}: {
|
either.map(convertDollarAmountToCountryCodeCurrency(amountInDollar)),
|
||||||
amountInDollar: number;
|
|
||||||
countryCode: CountryCode;
|
|
||||||
}) =>
|
|
||||||
pipe(
|
|
||||||
getCurrencyFromCountryCode(countryCode),
|
|
||||||
option.map(currency => {
|
|
||||||
const convertedDollarAmount = convertFromDollar(currency)(currency);
|
|
||||||
console.log(
|
|
||||||
`converted amount for country ${countryCode} is ${convertedAmount}`,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const convertDollarAmountInCountryCurrency = ({
|
|
||||||
amountInDollar,
|
|
||||||
countryName,
|
|
||||||
}: {
|
|
||||||
amountInDollar: number;
|
|
||||||
countryName: CountryName;
|
|
||||||
}) =>
|
|
||||||
pipe(
|
|
||||||
getCountryCode(countryName),
|
|
||||||
either.map(countryCode =>
|
|
||||||
convertDollarAmountToCountryCodeCurrency({ amountInDollar, countryCode }),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const convertDollarAmountInCountryCodeCurrency =
|
||||||
|
(amountInDollar: number) => (countryCode: CountryCode) =>
|
||||||
|
pipe(
|
||||||
|
getCurrencyFromCountryCode(countryCode),
|
||||||
|
option.map(convertFromDollarAmount(amountInDollar)),
|
||||||
|
option.map(convertedAmount =>
|
||||||
|
console.log(
|
||||||
|
`converted amount for country ${countryCode} is ${convertedAmount}`,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
```
|
```
|
||||||
|
|
Reference in a new issue