MCPcopy Index your code
hub / github.com/TanStack/virtual / proxyVirtualizer

Function proxyVirtualizer

packages/angular-virtual/src/proxy.ts:6–90  ·  view source on GitHub ↗
(
  virtualizerSignal: WritableSignal<V>,
  lazyInit: () => V,
)

Source from the content-addressed store, hash-verified

4import type { AngularVirtualizer } from './types'
5
6export function proxyVirtualizer<
7 V extends Virtualizer<any, any>,
8 S extends Element | Window = V extends Virtualizer<infer U, any> ? U : never,
9 I extends Element = V extends Virtualizer<any, infer U> ? U : never,
10>(
11 virtualizerSignal: WritableSignal<V>,
12 lazyInit: () => V,
13): AngularVirtualizer<S, I> {
14 return new Proxy(virtualizerSignal, {
15 apply() {
16 return virtualizerSignal()
17 },
18 get(target, property) {
19 const untypedTarget = target as any
20 if (untypedTarget[property]) {
21 return untypedTarget[property]
22 }
23 let virtualizer = untracked(virtualizerSignal)
24 if (virtualizer == null) {
25 virtualizer = lazyInit()
26 untracked(() => virtualizerSignal.set(virtualizer))
27 }
28
29 // Create computed signals for each property that represents a reactive value
30 if (
31 typeof property === 'string' &&
32 [
33 'getTotalSize',
34 'getVirtualItems',
35 'isScrolling',
36 'options',
37 'range',
38 'scrollDirection',
39 'scrollElement',
40 'scrollOffset',
41 'scrollRect',
42 'measureElementCache',
43 'measurementsCache',
44 ].includes(property)
45 ) {
46 const isFunction =
47 typeof virtualizer[property as keyof V] === 'function'
48 Object.defineProperty(untypedTarget, property, {
49 value: isFunction
50 ? computed(() => (target()[property as keyof V] as Function)())
51 : computed(() => target()[property as keyof V]),
52 configurable: true,
53 enumerable: true,
54 })
55 }
56
57 // Create plain signals for functions that accept arguments and return reactive values
58 if (
59 typeof property === 'string' &&
60 [
61 'getOffsetForAlignment',
62 'getOffsetForIndex',
63 'getVirtualItemForOffset',

Callers 1

createVirtualizerBaseFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected