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

Method remove

packages/db/src/indexes/basic-index.ts:115–144  ·  view source on GitHub ↗

* Removes a value from the index

(key: TKey, item: any)

Source from the content-addressed store, hash-verified

113 * Removes a value from the index
114 */
115 remove(key: TKey, item: any): void {
116 let indexedValue: any
117 try {
118 indexedValue = this.evaluateIndexExpression(item)
119 } catch (error) {
120 console.warn(
121 `Failed to evaluate index expression for key ${key} during removal:`,
122 error,
123 )
124 this.indexedKeys.delete(key)
125 this.updateTimestamp()
126 return
127 }
128
129 const normalizedValue = normalizeValue(indexedValue)
130
131 if (this.valueMap.has(normalizedValue)) {
132 const keySet = this.valueMap.get(normalizedValue)!
133 keySet.delete(key)
134
135 if (keySet.size === 0) {
136 // No more keys for this value, remove from map and sorted array
137 this.valueMap.delete(normalizedValue)
138 deleteInSortedArray(this.sortedValues, normalizedValue, this.compareFn)
139 }
140 }
141
142 this.indexedKeys.delete(key)
143 this.updateTimestamp()
144 }
145
146 /**
147 * Updates a value in the index

Callers 5

updateMethod · 0.95
rxdb.test.tsFile · 0.45
updateIndexesMethod · 0.45

Calls 5

normalizeValueFunction · 0.85
deleteInSortedArrayFunction · 0.85
deleteMethod · 0.45
hasMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected