MCPcopy Index your code
hub / github.com/TanStack/db / createObjectProxy

Function createObjectProxy

packages/db/src/proxy.ts:811–1073  ·  view source on GitHub ↗
(obj: TObj)

Source from the content-addressed store, hash-verified

809
810 // Create a proxy for the target object
811 function createObjectProxy<TObj extends object>(obj: TObj): TObj {
812 debugLog(`createObjectProxy`, obj)
813 // If we've already created a proxy for this object, return it
814 if (proxyCache.has(obj)) {
815 debugLog(`proxyCache found match`)
816 return proxyCache.get(obj) as TObj
817 }
818
819 // Create a proxy for the object
820 const proxy = new Proxy(obj, {
821 get(ptarget, prop) {
822 debugLog(`get`, ptarget, prop)
823 const value =
824 changeTracker.copy_[prop as keyof T] ??
825 changeTracker.originalObject[prop as keyof T]
826
827 const originalValue = changeTracker.originalObject[prop as keyof T]
828
829 debugLog(`value (at top of proxy get)`, value)
830
831 // If it's a getter, return the value directly
832 const desc = Object.getOwnPropertyDescriptor(ptarget, prop)
833 if (desc?.get) {
834 return value
835 }
836
837 // If the value is a function, bind it to the ptarget
838 if (typeof value === `function`) {
839 // For Array methods that modify the array
840 if (Array.isArray(ptarget)) {
841 const methodName = prop.toString()
842
843 if (ARRAY_MODIFYING_METHODS.has(methodName)) {
844 return createModifyingMethodHandler(
845 value,
846 changeTracker,
847 markChanged,
848 )
849 }
850
851 // Handle array iteration methods (find, filter, forEach, etc.)
852 const iterationHandler = createArrayIterationHandler(
853 methodName,
854 value,
855 changeTracker,
856 memoizedCreateChangeProxy,
857 )
858 if (iterationHandler) {
859 return iterationHandler
860 }
861
862 // Handle array Symbol.iterator for for...of loops
863 if (prop === Symbol.iterator) {
864 return createArrayIteratorHandler(
865 changeTracker,
866 memoizedCreateChangeProxy,
867 )
868 }

Callers 1

createChangeProxyFunction · 0.85

Calls 4

debugLogFunction · 0.85
hasMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…