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

Function toComputed

packages/angular-table/src/proxy.ts:71–96  ·  view source on GitHub ↗

* Here we'll handle all type of accessors: * - 0 argument -> e.g. table.getCanNextPage()) * - 0~1 arguments -> e.g. table.getIsSomeRowsPinned(position?) * - 1 required argument -> e.g. table.getColumn(columnId) * - 1+ argument -> e.g. table.getRow(id, searchAll?) * * Since we are not able to d

(signal: Signal<Table<T>>, fn: Function)

Source from the content-addressed store, hash-verified

69 * that return it's value based on the given parameters
70 */
71function toComputed<T>(signal: Signal<Table<T>>, fn: Function) {
72 const hasArgs = fn.length > 0
73 if (!hasArgs) {
74 return computed(() => {
75 void signal()
76 return fn()
77 })
78 }
79
80 const computedCache: Record<string, Signal<unknown>> = {}
81
82 return (...argsArray: any[]) => {
83 const serializedArgs = serializeArgs(...argsArray)
84 if (computedCache.hasOwnProperty(serializedArgs)) {
85 return computedCache[serializedArgs]?.()
86 }
87 const computedSignal = computed(() => {
88 void signal()
89 return fn(...argsArray)
90 })
91
92 computedCache[serializedArgs] = computedSignal
93
94 return computedSignal()
95 }
96}
97
98function serializeArgs(...args: any[]) {
99 return JSON.stringify(args)

Callers 1

getFunction · 0.85

Calls 1

serializeArgsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…