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

Function toComputed

packages/angular-virtual/src/proxy.ts:92–113  ·  view source on GitHub ↗
(
  signal: Signal<V>,
  fn: Function,
)

Source from the content-addressed store, hash-verified

90}
91
92function toComputed<V extends Virtualizer<any, any>>(
93 signal: Signal<V>,
94 fn: Function,
95) {
96 const computedCache: Record<string, Signal<unknown>> = {}
97
98 return (...args: Array<any>) => {
99 // Cache computeds by their arguments to avoid re-creating the computed on each call
100 const serializedArgs = serializeArgs(...args)
101 if (computedCache.hasOwnProperty(serializedArgs)) {
102 return computedCache[serializedArgs]?.()
103 }
104 const computedSignal = computed(() => {
105 void signal()
106 return fn(...args)
107 })
108
109 computedCache[serializedArgs] = computedSignal
110
111 return computedSignal()
112 }
113}
114
115function serializeArgs(...args: Array<any>) {
116 return JSON.stringify(args)

Callers 1

getFunction · 0.85

Calls 1

serializeArgsFunction · 0.85

Tested by

no test coverage detected