Skip to content
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

[2단계 - Virtual DOM 만들기] 지그(송지은) 미션 제출합니다. #23

Merged
merged 1 commit into from
Oct 31, 2021

Conversation

zigsong
Copy link

@zigsong zigsong commented Oct 30, 2021

1단계에서 이미 useState를 구현했어서, 2단계 미션에서는 기존의 useState를 Proxy로 받아오도록 수정해보았습니다.

Counter 컴포넌트에서 더 이상 getState()로 직접 호출할 필요는 없지만,
state에 Proxy를 적용해주기 위해 state를 객체로 만들다보니 state.value와 같이 접근해야 하는 문제(?)는 있습니다

그래도 새로운 개념을 적용시켜본 것에 의의를... ㅎㅅㅎ

앱은 지난번과 같이 여기서 확인 가능합니다!

Copy link

@yujo11 yujo11 left a comment

Choose a reason for hiding this comment

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

1단계에 이미 많은걸 구현하셔서 그런지 2단계에서 코드 변화가 많지 않았네용

코드에 수정해야 할 사항은 찾지 못 해 바로 어프로브 남기겠습니다!

지그 코드 보면서 많이 배웠습니다!! 2단계 미션까지 고생하셨어요 지그!! 👍 👍 👍

Comment on lines +4 to +23
const [initialCount, setCount] = Zig.useState(0);

const count = new Proxy(initialCount, {
get(target, prop) {
try {
let value = target[prop];

return typeof target.value === 'function' ? value.call(target) : target.value;
} catch (error) {
console.error(`Proxy get Error: ${error}`);
}
},
});

const decrease = () => {
setCount(getCount() - 1);
setCount(count.value - 1);
};

const increase = () => {
setCount(getCount() + 1);
setCount(count.value + 1);
Copy link

Choose a reason for hiding this comment

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

프록시를 사용한다면 Zig.useState()를 아예 제거하고 Proxy 내부에 set 핸들러를 정의해서 사용하면 어떨까 하는 생각이 드네용

Copy link
Author

Choose a reason for hiding this comment

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

아하 그것도 좋은 생각이에요!!
이번 미션에서는 그냥 기존 React의 useState와 비슷하게 구현하고 싶어서 (setCount()의 형태로 쓰고 싶어서 ㅎㅅㅎ) 이렇게 두었습니다!!

의견 제시 고마와용 🤩

@yujo11 yujo11 merged commit 8e12756 into woowacourse:zigsong Oct 31, 2021
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.

2 participants