-
Notifications
You must be signed in to change notification settings - Fork 77
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
[12팀 정석호] [Chapter 1-1] 프레임워크 없이 SPA 만들기 #4
base: main
Are you sure you want to change the base?
[12팀 정석호] [Chapter 1-1] 프레임워크 없이 SPA 만들기 #4
Conversation
그만달아요~ :( |
😞 |
import { Footer } from "../components/Footer"; | ||
|
||
export const MainPage = { | ||
register: ({ router }) => { |
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.
석호님! 저 질문이 있는데 register와 render 메서드를 분리해서 구현하신 거 같은데 혹시 어떤 이유에서 하신 건지 궁금해요!
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.
render 하나로 퉁쳤었는데, 이벤트 등록 때문에 분리 했습니다.
사실 #root 에 모두 위임해두면 render 하나로 퉁 칠 수 있습니다.
그런데 테스트 코드 구현체에서 submit 을 직접 참조해서 이벤트를 dispatch 하는 경우가 있어서 이벤트 위임으로 해결되지 않은 이벤트가 있었고, 반드시 document.body 에 DOM 이 생성되고 나서 이벤트를 등록해야하는 상황이 발생했습니다.
그래서 어쩔수 없이 그냥 render 와 resgister 를 분리하기로 했습니다 ㅠ 울며 겨자먹으며
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.
먼저 구현완료하시고 추가로 옵저버패턴 적용하신다고 리팩토링하시는 거에 감명받았습니다..🔥
이번주 구현 작업하시느라 고생하셨습니다!
|
||
export function createApp({ renderCurrentPage }) { | ||
function render() { | ||
document.getElementById("root").addEventListener("click", (e) => { |
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.
다른 리스너들과는 다르게 앵커를 app.js에서 선언해주신게 전체적인 페이지에서 헤더를 쓰고 있어서 선언해두신게 맞을까요?? 그러면 전역적으로 사용되는 이벤트리스너들이 있다고 판단하면 렌더 단계에서 모두 선언하면 되는 지가 궁금합니다!
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.
넵 생각하신대로 "a 태그를 누르면 페이지 이동이 SPA 처럼 된다"라는 기능이 페이지 종속적인 기능이 아니라서 전역에 처리해준 게 맞습니다. 방법은 다양할 것 같긴 해유. 어차피 이벤트 위임으로 #root 만 있으면 동작하는 이벤트라 렌더링 맨 위에 올려둬도 문제가 없기도 하고 // 다 로드되고 이벤트 등록해고 괜찮을 것 같긴 합니다
export function withObserver(instance = {}) { | ||
const observers = []; | ||
|
||
instance.subscribe = function (observer) { | ||
observers.push(observer); | ||
}; | ||
|
||
instance.notify = function () { | ||
observers.forEach((x) => x.update(instance)); | ||
}; | ||
|
||
return instance; | ||
} |
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.
withObserver 하나로 페이지 렌더링, 라우터, 스토어 구독을 전부 해결하신 거군요...! 👍🏻
(기록용)
스토어에 persistent 기능이 들어간 게 사실 이후에 추가한 동작인데, 생각해보니 persistent 기능만 쓰고 있어서 기본으로 내장했었어요! 그런데 마지막에 기본으로 내장해놓고 파라미터를 지우는 걸 잊었네요 🥲 감사합니다!
오,,!! 맞습니다. 지금은 일단 그냥 set / clear 함수가 호출 되기만 하면 notify 가 호출되네요! 감사합니다 :) |
(기록용)
말씀하신대로 PR 문서를 잘 가꿔두면 좋겠네요! 다음 PR 부터는 좀 더 잘 작성해볼게요! 👍 👍 👍 |
회고까지 또 하시고.. 최고입니다 👍🏼👍🏼 저도 배울게요🙏🏿🙏🏿 |
안녕하세요, 4기 12팀 정석호입니다. 잘 부탁드립니다. 🙃 🙌
과제 체크포인트
기본과제
1) 라우팅 구현:
2) 사용자 관리 기능:
3) 프로필 페이지 구현:
4) 컴포넌트 기반 구조 설계:
5) 상태 관리 초기 구현:
6) 이벤트 처리 및 DOM 조작:
7) 라우팅 예외 처리:
심화과제
1) 해시 라우터 구현
2) 라우트 가드 구현
3) 이벤트 위임
과제 셀프회고
기술적 성장
History API
를 통한Hash Router
작업이나Observer 패턴
를 실제 상황에 맞게 도입해본 적 없이 들어만 봐왔는데, 이번 기회에 시도해보고 싶은 기술들 다 시도해보면서 TestCase를 통과해내는 결과를 낸 것 같아 기쁩니다.코드 품질
👍 HoF + Observer 패턴
과제 피드백
리뷰 받고 싶은 내용
Observer 패턴