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

Function saveToStorage

packages/db/src/local-storage.ts:399–417  ·  view source on GitHub ↗
(
    dataMap: Map<string | number, StoredItem<any>>,
  )

Source from the content-addressed store, hash-verified

397 * @param dataMap - Map of items with version tracking to save to storage
398 */
399 const saveToStorage = (
400 dataMap: Map<string | number, StoredItem<any>>,
401 ): void => {
402 try {
403 // Convert Map to object format for storage
404 const objectData: Record<string, StoredItem<any>> = {}
405 dataMap.forEach((storedItem, key) => {
406 objectData[encodeStorageKey(key)] = storedItem
407 })
408 const serialized = parser.stringify(objectData)
409 storage.setItem(config.storageKey, serialized)
410 } catch (error) {
411 console.error(
412 `[LocalStorageCollection] Error saving data to storage key "${config.storageKey}":`,
413 error,
414 )
415 throw error
416 }
417 }
418
419 /**
420 * Removes all collection data from the configured storage

Callers 4

wrappedOnInsertFunction · 0.85
wrappedOnUpdateFunction · 0.85
wrappedOnDeleteFunction · 0.85
acceptMutationsFunction · 0.85

Calls 3

encodeStorageKeyFunction · 0.85
setItemMethod · 0.80
forEachMethod · 0.45

Tested by

no test coverage detected