MCPcopy
hub / github.com/TanStack/query / signalProxy

Function signalProxy

packages/angular-query-experimental/src/signal-proxy.ts:14–46  ·  view source on GitHub ↗
(
  inputSignal: Signal<TInput>,
)

Source from the content-addressed store, hash-verified

12 * @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.
13 */
14export function signalProxy<TInput extends Record<string | symbol, any>>(
15 inputSignal: Signal<TInput>,
16) {
17 const internalState = {} as MapToSignals<TInput>
18
19 return new Proxy<MapToSignals<TInput>>(internalState, {
20 get(target, prop) {
21 // first check if we have it in our internal state and return it
22 const computedField = target[prop]
23 if (computedField) return computedField
24
25 // then, check if it's a function on the resultState and return it
26 const targetField = untracked(inputSignal)[prop]
27 if (typeof targetField === 'function') return targetField
28
29 // finally, create a computed field, store it and return it
30 // @ts-expect-error
31 return (target[prop] = computed(() => inputSignal()[prop]))
32 },
33 has(_, prop) {
34 return !!untracked(inputSignal)[prop]
35 },
36 ownKeys() {
37 return Reflect.ownKeys(untracked(inputSignal))
38 },
39 getOwnPropertyDescriptor() {
40 return {
41 enumerable: true,
42 configurable: true,
43 }
44 },
45 })
46}

Callers 4

createBaseQueryFunction · 0.90
injectQueriesFunction · 0.90
injectMutationFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…