-
Notifications
You must be signed in to change notification settings - Fork 2
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
[박상범] 챕터 7: 신뢰할 수 없는 코드를 쓰면서 불변성 지키기 #42
The head ref may contain hidden characters: "\uCC55\uD1307/\uBC15\uC0C1\uBC94"
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# 7장 - 신뢰할 수 없는 코드를 쓰면서 불변성 지키기 | ||
|
||
방어적 복사 : 안전하지 않은 코드(서드파티 or 레거시 코드)를 사용하기 전 / 후에 데이터를 복사해서 사용 | ||
|
||
## 깊은 복사는 얕은 복사보다 비싸다 | ||
|
||
![image](https://github.com/muhandojeon/Grokking-Simplicity/assets/43921054/53396dcf-78eb-4151-8ab3-43bf6573cb2a) | ||
|
||
![image](https://github.com/muhandojeon/Grokking-Simplicity/assets/43921054/94bcc75b-09a7-4885-afff-b015f2927de2) | ||
|
||
|
||
tanstack/query 에서 구조적 공유(structural share)는 어떻게 동작될까? | ||
|
||
- 해당 코드 : https://github.com/TanStack/query/blob/2aca521a882e54b01ee6a070cb4a38f38bfa4bcf/packages/query-core/src/utils.ts#L210-L253 | ||
- 코드 해석: | ||
|
||
**입력으로 `a`와 `b` 두 매개변수를 받으며, 이 두 매개변수가 완전히 동일할 경우 `a`를 반환** | ||
|
||
**만약, `a`와 `b`가 배열이거나 객체인 경우, 각 항목 또는 속성을 순회하며 다음을 수행:** | ||
|
||
- **배열 또는 객체의 모든 항목(또는 속성)을 비교** | ||
- **동일한 항목은 `a`에서 가져옴** | ||
- **`a`와 `b` 사이에 동일하지 않은 항목이 있다면, 그 항목에 대해 재귀적으로 `replaceEqualDeep` 함수를 호출하여 깊은 비교를 수행** | ||
- **만약 `a`와 `b`의 크기가 같고, 모든 항목이 동일하다면 원본 `a`를 반환** | ||
- **그렇지 않다면, 변경된 사본을 반환** | ||
|
||
**이 코드의 핵심은, 깊은 동일성(deep equality) 검사를 통해 불필요한 데이터 복사를 방지하고, 가능한 경우 원본 데이터 구조를 재사용하여 메모리 사용을 최적화하는 것. | ||
⇒ 큰 JSON 구조에서 데이터를 효율적으로 다루기 위함일 듯, 최적화 굿** | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
우왕 이런 것이 있는지 어떻게 아셨나요?!?!?! 궁금합니다!!!
공유 감사드려요!! 👍 👍
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.
tkdodo 블로그에 있었어요! 🙌🏻