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

Function processStorageChanges

packages/db/src/local-storage.ts:750–777  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

748 * Loads new data from storage, compares with last known state, and applies changes
749 */
750 const processStorageChanges = () => {
751 if (!syncParams) return
752
753 const { begin, write, commit } = syncParams
754
755 // Load the new data
756 const newData = loadFromStorage<T>(storageKey, storage, parser)
757
758 // Find the specific changes
759 const changes = findChanges(lastKnownData, newData)
760
761 if (changes.length > 0) {
762 begin()
763 changes.forEach(({ type, value }) => {
764 if (value) {
765 validateJsonSerializable(parser, value, type)
766 write({ type, value })
767 }
768 })
769 commit()
770
771 // Update lastKnownData
772 lastKnownData.clear()
773 newData.forEach((storedItem, key) => {
774 lastKnownData.set(key, storedItem)
775 })
776 }
777 }
778
779 const syncConfig: SyncConfig<T> & {
780 manualTrigger?: () => void

Callers 1

handleStorageEventFunction · 0.85

Calls 6

loadFromStorageFunction · 0.85
findChangesFunction · 0.85
validateJsonSerializableFunction · 0.85
forEachMethod · 0.45
clearMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected