-
Notifications
You must be signed in to change notification settings - Fork 20
[강석준] sprint4 #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[강석준] sprint4 #54
The head ref may contain hidden characters: "Basic-\uAC15\uC11D\uC900-sprint4"
Conversation
|
스프리트 미션 하시느라 수고 많으셨어요. |
| @@ -1,5 +1,5 @@ | |||
| @import "global.css"; | |||
| @import "reset.css"; | |||
| @import "global.css"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굿굿 ~! global.css를 후순위로 두셨군요 !
global.css를 후순위로 두셨군요 ! 이제 초기화를 한 후 전역적인 스타일을 적용되어 의도하신 우선순위대로 동작할 것으로 기대됩니다 !
| const ERROR_EMAIL_EMPTY = "이메일을 입력해주세요."; | ||
| const ERROR_EMAIL_PATTERN = "잘못된 이메일 형식입니다."; | ||
| const ERROR_PASSWORD_EMPTY = "비밀번호를 입력해주세요."; | ||
| const ERROR_PASSWORD_PATTERN = "비밀번호를 8자 이상 입력해주세요."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(제안) 해당 상수들은 객체로 선언해볼 수 있습니다 ! 😊:
| const ERROR_EMAIL_EMPTY = "이메일을 입력해주세요."; | |
| const ERROR_EMAIL_PATTERN = "잘못된 이메일 형식입니다."; | |
| const ERROR_PASSWORD_EMPTY = "비밀번호를 입력해주세요."; | |
| const ERROR_PASSWORD_PATTERN = "비밀번호를 8자 이상 입력해주세요."; | |
| ERROR_MESSAGES: { | |
| email: { | |
| empty: "이메일을 입력해주세요.", | |
| invalid: "잘못된 이메일 형식입니다.", | |
| }, | |
| password: { | |
| empty: "비밀번호를 입력해주세요.", | |
| invalid: "비밀번호를 8자 이상 입력해주세요.", | |
| }, | |
| }; |
한 곳에서 관리하고 스코프를 나누어 관리할 수 있어요 !
| const handleEmailFocusout = (e) => { | ||
| const email = e.target.value; | ||
|
|
||
| submitButton.disabled = !isFormFilled; | ||
| if (!isEmailValid(email)) { | ||
| applyClass(emailInputWrapper, "error"); | ||
| emailMsgContainer.textContent = isEmpty(email) | ||
| ? ERROR_EMAIL_EMPTY | ||
| : ERROR_EMAIL_PATTERN; | ||
| return; | ||
| } else { | ||
| removeClass(emailInputWrapper, "error"); | ||
| emailMsgContainer.textContent = ""; | ||
| } | ||
|
|
||
| submitButton.disabled = !isFormValid(); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오호. 이벤트 핸들러 함수와 유효성 검사 함수를 분리하셨군요?
함수들의 목표가 명확하군요 👍
| applyClass(emailInputWrapper, "error"); | ||
| emailMsgContainer.textContent = isEmpty(email) | ||
| ? ERROR_EMAIL_EMPTY | ||
| : ERROR_EMAIL_PATTERN; | ||
| return; | ||
| } else { | ||
| removeClass(emailInputWrapper, "error"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applyClass, removeClass .. 유틸 함수도 만드셨군요 😊
굿굿. 엘리먼트와 클래스명을 받아서 클래스 이름을 추가/삭제 하는 역할로 보이네요.
응용력이 좋으십니다. 👍👍
| let visible = false; | ||
|
|
||
| return function onClickToggleButton() { | ||
| visible = !visible; | ||
|
|
||
| input.type = visible ? "text" : "password"; | ||
| image.src = visible ? IMG_VISIBLE_ON : IMG_VISIBLE_OFF; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(선택/의견/제안) 클로저 활용까지 !
visible을 함수 바깥에 설정하여 클로저를 활용하여 디스플레이를 변경하고 있군요 !
장단점이 있으므로 선택적 제안을 드리자면 data-attribute를 사용해볼 수 도 있을 것 같아요.
| let visible = false; | |
| return function onClickToggleButton() { | |
| visible = !visible; | |
| input.type = visible ? "text" : "password"; | |
| image.src = visible ? IMG_VISIBLE_ON : IMG_VISIBLE_OFF; | |
| }; | |
| export const toggleVisibility = (input, image) => { | |
| const isVisible = input.getAttribute("data-visible") === "true"; | |
| const nextState = !isVisible; | |
| input.type = nextState ? "text" : "password"; | |
| image.src = nextState ? IMG_VISIBLE_ON : IMG_VISIBLE_OFF; | |
| input.setAttribute("data-visible", nextState); | |
| }; |
| const handleConfirmPwdFocusout = (e) => { | ||
| const pwd = pwdInput.value; | ||
| const confirmPwd = e.target.value; | ||
|
|
||
| if (!isPwdMatched(pwd, confirmPwd)) { | ||
| applyClass(confirmPwdInputWrapper, "error"); | ||
| confirmPwdMsgContainer.textContent = ERROR_PASSWORD_MISMATCH; | ||
| return; | ||
| } else { | ||
| removeClass(confirmPwdInputWrapper, "error"); | ||
| confirmPwdMsgContainer.textContent = ""; | ||
| } | ||
|
|
||
| submitButton.disabled = !isFormValid(); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(선택) 이미 if에 return을 해주고 있기 때문에 else는 불필요해보입니다 !
| const handleConfirmPwdFocusout = (e) => { | |
| const pwd = pwdInput.value; | |
| const confirmPwd = e.target.value; | |
| if (!isPwdMatched(pwd, confirmPwd)) { | |
| applyClass(confirmPwdInputWrapper, "error"); | |
| confirmPwdMsgContainer.textContent = ERROR_PASSWORD_MISMATCH; | |
| return; | |
| } else { | |
| removeClass(confirmPwdInputWrapper, "error"); | |
| confirmPwdMsgContainer.textContent = ""; | |
| } | |
| submitButton.disabled = !isFormValid(); | |
| }; | |
| const handleConfirmPwdFocusout = (e) => { | |
| const pwd = pwdInput.value; | |
| const confirmPwd = e.target.value; | |
| if (!isPwdMatched(pwd, confirmPwd)) { | |
| applyClass(confirmPwdInputWrapper, "error"); | |
| confirmPwdMsgContainer.textContent = ERROR_PASSWORD_MISMATCH; | |
| return; | |
| } | |
| removeClass(confirmPwdInputWrapper, "error"); | |
| confirmPwdMsgContainer.textContent = ""; | |
| submitButton.disabled = !isFormValid(); | |
| }; |
| export const isEmailValid = (email) => emailRegex.test(email); | ||
| export const isPwdValid = (pwd) => pwdRegex.test(pwd); | ||
| export const isPwdMatched = (pwd, confirm) => pwd === confirm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
크으.. 간결하고 컴팩트한 순수함수들 👍
순수함수: 순수 함수는 오직 함수의 입력만이 함수의 결과에 영향을 주며 사이드이펙트가 없는 함수예요.
|
우아 어째 칭찬만 하다가 끝나버렸어요. 미션 수행하시느라 정말 수고 많으셨습니다 석준님 ! 👍👍 |
요구사항
기본
로그인
회원가입
심화
주요 변경사항
멘토에게