-
Notifications
You must be signed in to change notification settings - Fork 3
Perf: 번들 사이즈 최적화 #30
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
Merged
Perf: 번들 사이즈 최적화 #30
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9ffc60d
chore: external bundle
976520 63685ab
fix: ecmascript 상 private field 사용
976520 ec7dc67
Update packages/core/src/strategies/layout/FixedLayoutStrategy.ts
976520 50fc103
fix: readonly
976520 cd1d69d
perf: 메모이제이션 추가
976520 d6e71d8
fix: | 0
976520 c3cf559
perf: Terser 세팅
976520 2d91236
refector: react 코드 간결화
976520 1ca240a
Update packages/core/tsup.config.ts
976520 973655b
chore: ts 2022->2020
976520 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
27 changes: 13 additions & 14 deletions
27
packages/core/src/strategies/layout/FixedLayoutStrategy.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,37 +1,36 @@ | ||
| import type { Range } from '../../types'; | ||
| import type { LayoutStrategy } from './LayoutStrategy'; | ||
| import { clamp } from '../../utils/clamp'; | ||
| import type { Range } from "../../types"; | ||
| import type { LayoutStrategy } from "./LayoutStrategy"; | ||
| import { clamp } from "../../utils/clamp"; | ||
|
|
||
| export class FixedLayoutStrategy implements LayoutStrategy { | ||
| constructor(private itemSize: number) {} | ||
| readonly #itemSize: number; | ||
|
|
||
| constructor(itemSize: number) { | ||
| this.#itemSize = itemSize; | ||
| } | ||
|
|
||
| getItemOffset(index: number): number { | ||
| return index * this.itemSize; | ||
| return index * this.#itemSize; | ||
| } | ||
|
|
||
| getItemSize(_index: number): number { | ||
| return this.itemSize; | ||
| return this.#itemSize; | ||
| } | ||
|
|
||
| getTotalSize(count: number): number { | ||
| return count * this.itemSize; | ||
| return count * this.#itemSize; | ||
| } | ||
|
|
||
| getVisibleRange( | ||
| scrollOffset: number, | ||
| viewportSize: number, | ||
| count: number | ||
| ): Range { | ||
| const startIndex = clamp( | ||
| 0, | ||
| Math.floor(scrollOffset / this.itemSize), | ||
| count - 1 | ||
| ); | ||
| const startIndex = clamp(0, (scrollOffset / this.#itemSize) | 0, count - 1); | ||
|
|
||
| const visibleCount = Math.ceil(viewportSize / this.itemSize); | ||
| const visibleCount = Math.ceil(viewportSize / this.#itemSize); | ||
| const endIndex = Math.min(count - 1, startIndex + visibleCount); | ||
|
|
||
| return { startIndex, endIndex }; | ||
| } | ||
| } | ||
|
|
30 changes: 15 additions & 15 deletions
30
packages/core/src/strategies/scroll/VirtualScrollSource.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -1,40 +1,40 @@ | ||
| import type { ScrollSource } from "./ScrollSource"; | ||
|
|
||
| export class VirtualScrollSource implements ScrollSource { | ||
| private scrollOffset = 0; | ||
| private viewportSize = 0; | ||
| private listeners = new Set<(offset: number) => void>(); | ||
| #scrollOffset = 0; | ||
| #viewportSize = 0; | ||
| #listeners = new Set<(offset: number) => void>(); | ||
|
|
||
| getScrollOffset(): number { | ||
| return this.scrollOffset; | ||
| return this.#scrollOffset; | ||
| } | ||
|
|
||
| getViewportSize(): number { | ||
| return this.viewportSize; | ||
| return this.#viewportSize; | ||
| } | ||
|
|
||
| setScrollOffset(offset: number): void { | ||
| if (this.scrollOffset !== offset) { | ||
| this.scrollOffset = offset; | ||
| this.notifyListeners(); | ||
| if (this.#scrollOffset !== offset) { | ||
| this.#scrollOffset = offset; | ||
| this.#notifyListeners(); | ||
| } | ||
| } | ||
|
|
||
| setViewportSize(size: number): void { | ||
| if (this.viewportSize !== size) { | ||
| this.viewportSize = size; | ||
| this.notifyListeners(); | ||
| if (this.#viewportSize !== size) { | ||
| this.#viewportSize = size; | ||
| this.#notifyListeners(); | ||
| } | ||
| } | ||
|
|
||
| subscribe(callback: (offset: number) => void): () => void { | ||
| this.listeners.add(callback); | ||
| this.#listeners.add(callback); | ||
| return () => { | ||
| this.listeners.delete(callback); | ||
| this.#listeners.delete(callback); | ||
| }; | ||
| } | ||
|
|
||
| private notifyListeners(): void { | ||
| this.listeners.forEach((listener) => listener(this.scrollOffset)); | ||
| #notifyListeners(): void { | ||
| this.#listeners.forEach((listener) => listener(this.#scrollOffset)); | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
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.
renderRange를 계산하는 방식이Math.max와Math.min을 사용하는 이전 코드에 비해 더 장황하고 가독성이 떨어집니다.visibleRange.startIndex와overscan이 모두 정수이므로| 0연산은 불필요하며,if조건문은Math.max/Math.min과 동일한 역할을 합니다. 코드의 명확성과 간결성을 위해 이전 방식으로 되돌리는 것을 제안합니다.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.
헐 진심?