Skip to content

Commit 5a6d720

Browse files
author
dasathyakuma
committed
Fix some review comments
1 parent 9bcc66f commit 5a6d720

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

examples/marko/grid/src/data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const ROW_COUNT = 1000
22
export const COL_COUNT = 1000
3-
export const rowSizes = Array.from({ length: ROW_COUNT }, () => 30 + Math.round(Math.random() * 20))
4-
export const colSizes = Array.from({ length: COL_COUNT }, () => 80 + Math.round(Math.random() * 80))
3+
export const rowSizes = Array.from({ length: ROW_COUNT }, (_, i) => 30 + ((i * 7 + 13) % 20))
4+
export const colSizes = Array.from({ length: COL_COUNT }, (_, i) => 80 + ((i * 11 + 17) % 80))

packages/marko-virtual/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ npm install @tanstack/marko-virtual
1212
pnpm add @tanstack/marko-virtual
1313
```
1414

15-
**Peer dependency:** `marko >= 6.0.0`
15+
**Peer dependency:** `marko ^6.0.0`
1616

1717
## Setup
1818

packages/marko-virtual/src/marko.d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@ declare module "*.marko" {
1313
export default template
1414
}
1515

16-
// Type declaration for @marko/vite plugin.
17-
// The actual package may ship its own types; this is a fallback.
16+
// Type declarations for @marko/vite and @marko/run/vite.
17+
// Both export the same Vite plugin factory; @marko/run/vite re-exports from
18+
// @marko/vite. Users may import from either path depending on their setup.
19+
// The actual packages may ship their own types; these are fallbacks.
1820
declare module "@marko/vite" {
1921
import type { Plugin } from "vite"
2022

23+
function marko(options?: Record<string, unknown>): Plugin
24+
export default marko
25+
}
26+
27+
declare module "@marko/run/vite" {
28+
import type { Plugin } from "vite"
29+
2130
function marko(options?: Record<string, unknown>): Plugin
2231
export default marko
2332
}

packages/marko-virtual/src/tags/virtualizer/index.marko

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ export interface Input {
9999
onDestroy() {
100100
const entry = getInstance(id)
101101
if (entry) {
102-
entry.cleanup()
103-
deleteInstance(id)
102+
try {
103+
entry.cleanup()
104+
} finally {
105+
deleteInstance(id)
106+
}
104107
}
105108
}
106109
/>

packages/marko-virtual/src/tags/window-virtualizer/index.marko

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,17 @@ export interface Input {
8686
})
8787
8888
v._willUpdate()
89+
notify()
8990
}
9091

9192
onDestroy() {
9293
const entry = getInstance(id)
9394
if (entry) {
94-
entry.cleanup()
95-
deleteInstance(id)
95+
try {
96+
entry.cleanup()
97+
} finally {
98+
deleteInstance(id)
99+
}
96100
}
97101
}
98102
/>

packages/marko-virtual/tests/index.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
* Marko compilation pipeline. Those are not set up here but should be added
1111
* as e2e tests using @marko/run's test utilities in a future iteration.
1212
*/
13-
import { describe, test, expect, beforeEach, vi } from 'vitest'
13+
import { beforeEach, describe, expect, test, vi } from 'vitest'
1414
import {
15-
Virtualizer,
15+
defaultKeyExtractor,
16+
defaultRangeExtractor,
1617
elementScroll,
17-
observeElementRect,
1818
observeElementOffset,
19-
observeWindowRect,
19+
observeElementRect,
2020
observeWindowOffset,
21+
observeWindowRect,
22+
Virtualizer,
2123
windowScroll,
22-
defaultRangeExtractor,
23-
defaultKeyExtractor,
2424
} from '../src/index'
2525

2626
// ---------------------------------------------------------------------------
@@ -167,9 +167,11 @@ describe('row virtualizer', () => {
167167
onChange,
168168
})
169169

170-
v._didMount()
170+
const cleanup = v._didMount()
171171
v._willUpdate()
172172
expect(onChange).toHaveBeenCalled()
173+
174+
cleanup()
173175
})
174176
})
175177

packages/marko-virtual/tests/tags.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,20 @@ const WindowVirtualizer = WindowVirtualizerFixture as any
3737
// Test helpers
3838
// ---------------------------------------------------------------------------
3939

40+
const instances: Array<{ destroy(): void }> = []
41+
4042
function mountFixture(Template: any, input: Record<string, unknown> = {}) {
4143
const container = document.createElement("div")
4244
document.body.appendChild(container)
43-
Template.mount(input, container)
45+
const instance = Template.mount(input, container)
46+
instances.push(instance)
4447
return container
4548
}
4649

4750
afterEach(() => {
48-
// Reset DOM between tests
51+
// Destroy Marko instances to run onDestroy lifecycle (cleans up store entries)
52+
instances.forEach((i) => i.destroy())
53+
instances.length = 0
4954
document.body.innerHTML = ""
5055
})
5156

0 commit comments

Comments
 (0)