::ExportFx
::
Chapter 2: FxTs
자바스크립트 함수형 라이브러리 FxTs를 사용해보기
1. 유저 정보 입력
여러 단계를 거쳐서 유저의 정보를 입력하는 로직
const getFlatUser = pipeLazy(
setPersonalInfo,
setAddress,
setFlatInfo,
isOwner,
)({ product: 'HOME_FLAT' });
const getHouseUser = pipeLazy(
setPersonalInfo,
setAddress,
setHouseInfo,
setOutbuildingSize,
setInstallations,
isOwner,
)({ product: 'HOME_HOUSE' });
const flatUser = getFlatUser();
const houseUser = getHouseUser();
2. 이메일 체크 예제
const EMAIL_REGEX =
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
const EmailAPI = {
async check(email) {
const isValid = !!email.match(EMAIL_REGEX);
await delay(500);
return isValid ? { email, format_valid: true } : { email, format_valid: false };
},
};
const emails = [
'Tee@gmail.com',
'Tom@gmail.com',
'Tommy@gmail.com',
'Mas@gmail.com',
'this.is.not.valid.email.com', // Invalid email
'Moz@gmail.com',
'Thom@gmail.com',
'Tomzy@gmail.com',
'Tizzy@gmail.com',
'T-mas@gmail.com',
'Mars@gmail.com',
];
const checkEmail = pipeLazy(
toAsync,
map(EmailAPI.check),
concurrent(3),
peek(console.log),
toArray,
);
await checkEmail(emails);