Skip to content

Conversation

@shoveller
Copy link

훌륭한 코드입니다!
각각의 코드가 해야하는 일을 정확히 알고 있고 군더더기가 없습니다.
폼을 사용할 때, 폼이 내장하고 있는 자체 기능을 좀 더 사용하면 좋을 것 같습니다.
그리고 else 와 삼항연산자 사용만 조금 줄이면 좋겠습니다.

@netlify
Copy link

netlify bot commented Feb 1, 2024

Deploy Preview for taaing ready!

Name Link
🔨 Latest commit dfcd9fd
🔍 Latest deploy log https://app.netlify.com/sites/taaing/deploys/65bafb44e5a8090008dddb7c
😎 Deploy Preview https://deploy-preview-86--taaing.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 16 to 24
async function findId(e) {
e.preventDefault();

const emailValue = inputEmail.value;
const formData = new FormData(e.currentTarget);
const { email } = Object.fromEntries(formData.entries());

try {
const res = await getData('users', {
filter: `email='${emailValue}'`,
filter: `email='${email}'`,
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

거의 다 왔습니다.
form 의 submit 이벤트 사용법을 이해했다면, form 에서 값을 꺼내오는 방법을 배울 차례입니다.

Comment on lines +37 to 55
const isValidEmail = (emailValue) => {
const regexEmail = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const emailValue = inputEmail.value;

if (regexEmail.test(emailValue) || emailValue === '') {
return regexEmail.test(emailValue) || emailValue === '';
};

/**
* TODO: 하나의 함수가 세가지 일을 하고 있군요.
* 1. 이메일 벨리데이션
* 2. 벨리데이션이 실패했을 때의 화면 처리
* 3. 벨리데이션이 성공했을 때의 화면 처리
* 적절하게 추상화해서 함수를 분리하는 것이 좋겠습니다.
* 2와 3항목도 분리해 보시면 어떨까요?
*/
function validateEmail() {
if (isValidEmail(inputEmail.value)) {
emailErrorNotice.classList.remove('block');
emailErrorNotice.classList.add('hidden');
submitButton.classList.remove('bg-button-submit-default');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수 하나가 세가지 일을 하고 있군요.
함수의 이름을 동사로 바꾸고 벨리데이션 함수만 분리해 보았습니다.
이제 if 블록에 있는 내용물과 else 블록에 있는 내용을 다른 함수로 분리해 보세요.
스스로의 행동을 설명하는 코드가 될 것이라 생각합니다.

Comment on lines 27 to +30
async function findId(e) {
e.preventDefault();

const userIdValue = inputUserId.value;
const formData = new FormData(e.currentTarget);
const { userId } = Object.fromEntries(formData.entries());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

폼의 이벤트에서 값을 읽어보면 이벤트 핸들러가 순수함수가 된다는 장점이 있지요.


// 데이터를 가져오는 함수
async function getData(collectionName, options = {}) {
export async function getData(collectionName, options = {}) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개인적으로는 눈알이 움직이는 에너지도 아끼기 위해 함수 선언에 export 를 붙입니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant