MCPcopy Create free account
hub / github.com/TanStack/db / collectFilteredResults

Function collectFilteredResults

packages/db/src/collection/change-events.ts:66–81  ·  view source on GitHub ↗
(
    filterFn?: (value: WithVirtualProps<T, TKey>) => boolean,
  )

Source from the content-addressed store, hash-verified

64): Array<ChangeMessage<WithVirtualProps<T, TKey>, TKey>> | void {
65 // Helper function to collect filtered results
66 const collectFilteredResults = (
67 filterFn?: (value: WithVirtualProps<T, TKey>) => boolean,
68 ): Array<ChangeMessage<WithVirtualProps<T, TKey>, TKey>> => {
69 const result: Array<ChangeMessage<WithVirtualProps<T, TKey>, TKey>> = []
70 for (const [key, value] of collection.entries()) {
71 // If no filter function is provided, include all items
72 if (filterFn?.(value) ?? true) {
73 result.push({
74 type: `insert`,
75 key,
76 value,
77 })
78 }
79 }
80 return result
81 }
82
83 // Validate that limit without orderBy doesn't happen
84 if (options.limit !== undefined && !options.orderBy) {

Callers 1

currentStateAsChangesFunction · 0.85

Calls 2

filterFnFunction · 0.85
entriesMethod · 0.45

Tested by

no test coverage detected