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

Function createArrayIteratorHandler

packages/db/src/proxy.ts:184–229  ·  view source on GitHub ↗

* Creates a Symbol.iterator handler for arrays that yields proxied elements.

(
  changeTracker: ChangeTracker<T>,
  memoizedCreateChangeProxy: (
    obj: Record<string | symbol, unknown>,
    parent?: {
      tracker: ChangeTracker<Record<string | symbol, unknown>>
      prop: string | symbol
    },
  ) => { proxy: Record<string | symbol, unknown> },
)

Source from the content-addressed store, hash-verified

182 * Creates a Symbol.iterator handler for arrays that yields proxied elements.
183 */
184function createArrayIteratorHandler<T extends object>(
185 changeTracker: ChangeTracker<T>,
186 memoizedCreateChangeProxy: (
187 obj: Record<string | symbol, unknown>,
188 parent?: {
189 tracker: ChangeTracker<Record<string | symbol, unknown>>
190 prop: string | symbol
191 },
192 ) => { proxy: Record<string | symbol, unknown> },
193): () => Iterator<unknown> {
194 return function () {
195 const array = changeTracker.copy_ as unknown as Array<unknown>
196 let index = 0
197
198 return {
199 next() {
200 if (index >= array.length) {
201 return { done: true, value: undefined }
202 }
203
204 const element = array[index]
205 let proxiedElement = element
206
207 if (isProxiableObject(element)) {
208 const nestedParent = {
209 tracker: changeTracker as unknown as ChangeTracker<
210 Record<string | symbol, unknown>
211 >,
212 prop: String(index),
213 }
214 const { proxy: elementProxy } = memoizedCreateChangeProxy(
215 element,
216 nestedParent,
217 )
218 proxiedElement = elementProxy
219 }
220
221 index++
222 return { done: false, value: proxiedElement }
223 },
224 [Symbol.iterator]() {
225 return this
226 },
227 }
228 }
229}
230
231/**
232 * Creates a wrapper for methods that modify a collection (array, Map, Set).

Callers 1

getFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…