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

Method set

packages/db/src/SortedMap.ts:92–107  ·  view source on GitHub ↗

* Sets a key-value pair in the map and maintains sort order * * @param key - The key to set * @param value - The value to associate with the key * @returns This SortedMap instance for chaining

(key: TKey, value: TValue)

Source from the content-addressed store, hash-verified

90 * @returns This SortedMap instance for chaining
91 */
92 set(key: TKey, value: TValue): this {
93 if (this.map.has(key)) {
94 // Need to remove the old key from the sorted keys array
95 const oldValue = this.map.get(key)!
96 const oldIndex = this.indexOf(key, oldValue)
97 this.sortedKeys.splice(oldIndex, 1)
98 }
99
100 // Insert the new key at the correct position
101 const index = this.indexOf(key, value)
102 this.sortedKeys.splice(index, 0, key)
103
104 this.map.set(key, value)
105
106 return this
107 }
108
109 /**
110 * Gets a value by its key

Callers

nothing calls this directly

Calls 3

indexOfMethod · 0.95
hasMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected